Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pitfall when using rand with Bevy on WASM #1923

Closed
zaszi opened this issue Apr 14, 2021 · 2 comments
Closed

Pitfall when using rand with Bevy on WASM #1923

zaszi opened this issue Apr 14, 2021 · 2 comments
Labels
C-Dependencies A change to the crates that Bevy depends on O-Web Specific to web (WASM) builds

Comments

@zaszi
Copy link
Contributor

zaszi commented Apr 14, 2021

For most random number generation needs, people simply grab the latest version of the rand crate. For this to work on WASM, upstream (for reasons I don't understand) ditched their WASM feature flag and now expect you to override their dependency manually and toggle the feature flag yourself, as mentioned rather obscurely upstream here:

rand = "0.8"
getrandom = {version="0.2", features=["js"]}

Except in the case of Bevy 0.4 this doesn't actually work because bevy_ecs depends on rand 0.7 which depends on getrandom 0.1. So people get a thread_rng or similar panic in the browser and are none the wiser despite following upstream instructions. Figuring this out is pretty painful. This actually does work:

rand = "0.8"
getrandom = {version="0.1", features=["wasm-bindgen"]}

This specific issue no longer occurs with Bevy 0.5 due to bevy_ecs now also depending on rand 0.8. However, this will potentially still cause problems in the future. If rand releases version 0.9 tomorrow and people start using it, the same problem will occur until Bevy catches up. Of course this is not a bug in Bevy itself, and it's not like there is no fix. But it's easy to run into this problem unknowingly and difficult enough to troubleshoot that I think it's worth highlighting here. Not to mention that having to care about a dependency of a dependency is uninuitive at best.

When it was discussed on Discord, the consensus was to take this up with the maintainers of rand. I'll leave this open for a bit for people to chime in, after which it can perhaps function as a tracking issue if it needs escalating upstream.

@zaszi zaszi added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Apr 14, 2021
@mockersf mockersf added O-Web Specific to web (WASM) builds C-Dependencies A change to the crates that Bevy depends on and removed C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Apr 14, 2021
@lberrymage
Copy link
Contributor

Without looking very deep into this, I think #1376 is related.

@alice-i-cecile
Copy link
Member

Closing as duplicate of #1376.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-Dependencies A change to the crates that Bevy depends on O-Web Specific to web (WASM) builds
Projects
None yet
Development

No branches or pull requests

4 participants