Skip to content

Bevy does not start on WASM because of the rand crates. #1376

Closed
@codec-abc

Description

@codec-abc

Bevy version

"0.4.0"

Operating system & version

Windows 10 and building for WASM.

What you did

I created a basic project to play with Seed (a Rust wasm framework) and Bevy to see how the 2 could interoperate. As I ran into other issues with Bevy I tried to setup a project for reproducing the bug. When I removed the Seed dependency another bug showed up (this one).

What you expected to happen

In this repository I set up the project is working fine as it is. But it contains Seed as a dependency that isn't needed. I expected to run just the same when removing the Seed dependency. Instead I got a crash with this error:

package.js:367 hello world
package_bg.wasm:0x13306b4 Uncaught (in promise) RuntimeError: unreachable
    at rust_start_panic (http://127.0.0.1:8000/static/package_bg.wasm:wasm-function[96256]:0x13306b4)
    at rust_panic (http://127.0.0.1:8000/static/package_bg.wasm:wasm-function[88735]:0x12fb685)
    at std::panicking::rust_panic_with_hook::hc5713da015ebaa19 (http://127.0.0.1:8000/static/package_bg.wasm:wasm-function[19582]:0xc80a7a)
    at std::panicking::begin_panic_handler::{{closure}}::hc5eba7f0030e8f4f (http://127.0.0.1:8000/static/package_bg.wasm:wasm-function[84877]:0x12d12fc)
    at std::sys_common::backtrace::rust_end_short_backtrace::he811f0bd07938b42 (http://127.0.0.1:8000/static/package_bg.wasm:wasm-function[85867]:0x12dd102)
    at rust_begin_unwind (http://127.0.0.1:8000/static/package_bg.wasm:wasm-function[76786]:0x1266ab9)
    at std::panicking::begin_panic_fmt::h308260c2e5b91752 (http://127.0.0.1:8000/static/package_bg.wasm:wasm-function[84876]:0x12d12c3)
    at rand::rngs::thread::THREAD_RNG_KEY::init::{{closure}}::h0d5a160d272afa5c (http://127.0.0.1:8000/static/package_bg.wasm:wasm-function[22564]:0xd1ee8e)
    at core::result::Result<T,E>::unwrap_or_else::h0acb8f77032d9da3 (http://127.0.0.1:8000/static/package_bg.wasm:wasm-function[5362]:0x7a5162)
    at rand::rngs::thread::THREAD_RNG_KEY::init::hb4d7b1557044de65 (http://127.0.0.1:8000/static/package_bg.wasm:wasm-function[9958]:0x9c051e)

To sum up, if you use the repo linked earlier, it will run fine as it is. When you edit the Cargo.toml to remove the Seed dependency it still build fine but crash at runtime while it shouldn't

Additional information

The call stack and some messages here and here on the Bevy discord seems to indicate that is a buggy version of the rand crate (or one of its dependencies). This would explain why it works with Seed. Since it uses rand it might trigger another version to be used which doesn't have this bug.

What could improve the situation is to pin exact version of the random crates that are known to work with WASM

PS: Thanks to Alice and DJMcNab on the Discord server for helping newcomers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-BugAn unexpected or incorrect behaviorC-DependenciesA change to the crates that Bevy depends onO-WebSpecific to web (WASM) builds

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions