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

Chrome or Edge (Webkit) Out of Memory (oom) crash within seconds of WASM bevy builds #4329

Open
JCBuck opened this issue Mar 25, 2022 · 4 comments
Labels
C-Bug An unexpected or incorrect behavior C-Docs An addition or correction to our documentation O-Web Specific to web (WASM) builds P-Crash A sudden unexpected crash

Comments

@JCBuck
Copy link

JCBuck commented Mar 25, 2022

Bevy version

Tested with Main branch with commit ab83336f along with release-0.6.1 @ 6acf932c

Operating system & version

Windows 10 21H2
Chrome 98.0.4758.102 (Official Build) (64-bit)

What you did

Essentially followed the WASM section of the examples readme.
I used these commands to build the text_debug example, without the --no-default-features flag, or else it wouldn't build. Modified index.html to point to wasm_example.js after building. Launched with basic-http-server examples/wasm

 cargo build --example text_debug --target wasm32-unknown-unknown
 wasm-bindgen --out-name wasm_example  --out-dir examples/wasm/target --target web target/wasm32-unknown-unknown/debug/examples/text_debug.wasm

What you expected to happen

Expected The text_debug example to launch and render in the browser.

What actually happened

It would launch and render for a few seconds, while being very stuttery then the tab would crash from and out of memory error.

Additional information

It would happen with any of the example projects.
Came across this reddit post describing this workaround which I tested working:
set in Cargo.toml

[profile.dev] 
opt-level = 2

Creating this issue since I didn't see one yet as requested in
https://www.reddit.com/r/rust/comments/s06vx3/how_to_get_a_developerfriendly_workflow_with_bevy/hs0228d/

@JCBuck JCBuck added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Mar 25, 2022
@mockersf
Copy link
Member

For wasm, I would recommend building either with --release, or with opt-level = 3.

Does it work with the commands from the readme?

bevy/examples/README.md

Lines 398 to 399 in 28ba87e

cargo build --release --example lighting --target wasm32-unknown-unknown
wasm-bindgen --out-name wasm_example --out-dir examples/wasm/target --target web target/wasm32-unknown-unknown/release/examples/lighting.wasm

It has been updated in main but not yet for the other branches

@JCBuck
Copy link
Author

JCBuck commented Mar 25, 2022

Thanks for the quick response.
Building with --release runs in chrome without out of memory crashes without needing to put opt-level = 2 or opt-level = 3 in the Cargo.toml

I'm using portable VSCode on Windows 10 with the codelldb plugin on the autogenerated launch.json, but modified to include wasm target and added the --release to reflect the example readme. It doesn't use codelldb for debugging, only as a makeshift method to quickly compile and bind for wasm, then launch basic-http-server to listen on all interfaces 0.0.0.0:4000

        {
            "type": "lldb",
            "request": "launch",
            "name": "Run WASM example 'text_debug'",
            "cargo": {
                "args": [
                    "build",
                    "--example=text_debug",
                    "--package=bevy",
                    "--release",
                    "--target=wasm32-unknown-unknown"
                ],
                "filter": {
                    "name": "sprite",
                    "kind": "example"
                }
            },
            
            "program": "cmd.exe",
            "args": ["/s", "/c", "echo Starting wasm-bindgen... ${cargo:program}  && wasm-bindgen --out-name wasm_example --out-dir examples/wasm/target --target web ${cargo:program} && echo Starting basic http server with wmic to prevent vscode terminal blocking on child process... && >nul wmic process call create 'cmd /c basic-http-server -a 0.0.0.0:4000 examples/wasm','%cd%'"],
            "cwd": "${workspaceFolder}"
        }

edit: changed sprite to text_debug to reflect tested example, but otherwise made a copy of this launch configuration for every example
edit 2:
reply on discord from Prawl about using opt-level = 3 in Cargo.toml instead of --release when running cargo build:

This might work even better for you:

[profile.dev.package."*"]
opt-level = 3

It makes only dependencies build with release optimizations but leaves your code at debug optimizations so it compiles fast after dependencies are built once. Great for Wasm builds. I was getting out of memory errors on debug builds before also. (Win 11 Chrome)
Found it this in this comment: #1206 (comment)

I think further explanations from the unofficial bevy cheatbook: https://bevy-cheatbook.github.io/pitfalls/performance.html

@alice-i-cecile alice-i-cecile added O-Web Specific to web (WASM) builds P-Crash A sudden unexpected crash C-Docs An addition or correction to our documentation and removed S-Needs-Triage This issue needs to be labelled labels Mar 25, 2022
@JCBuck
Copy link
Author

JCBuck commented Mar 28, 2022

Observed the same behavior as described in #3867 where it didn't crash in debug builds (with no explicit optimization levels) if i had the dev tools open.

@slothlockholmes
Copy link

slothlockholmes commented Mar 30, 2022

Hi everyone, I am running into a similar issue as well.

Bevy version

0.6.0

Operating system & version

Ubuntu 20.04

What you did

  1. cargo new new_project
  2. Copied the code for https://bevyengine.org/examples/game/breakout/ into main.rs
  3. Added bevy = "0.6" into Cargo.toml
  4. Followed the tutorial here https://bevy-cheatbook.github.io/platforms/wasm.html#quick-start to start a minimal local webserver

What you expected to happen

The game not to crash on the browser

What actually happened

Exactly as described by @JCBuck . It would launch and render for a few seconds, while being very stuttery then the tab would crash from and out of memory error.

Additional information

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-Bug An unexpected or incorrect behavior C-Docs An addition or correction to our documentation O-Web Specific to web (WASM) builds P-Crash A sudden unexpected crash
Projects
None yet
Development

No branches or pull requests

4 participants