gdnative icon indicating copy to clipboard operation
gdnative copied to clipboard

Debug builds don't work on web

Open necrashter opened this issue 2 years ago • 1 comments

Exporting the Hello World project to Web with debug mode causes the game to crash on start-up with the following error on Firefox:

wasm validation error: at offset 838450: too many locals

And with the following on Brave browser:

WebAssembly.instantiate(): Compiling function #2262:"gdnative_sys::GodotApi::from_raw::h2b788ea99960..." failed: local count too large @+838449

Presumably, this happens due to library size. .wasm file size is 280 kB on release, 21.8 MB on debug. For reference, godot.side.wasm is 19.2 MB in 3.5.1 and 14.8 MB in my custom build.

Using the master version of this repository (commit 91e1b77340d02c4b151b0527062d544a0d08f17e) with Godot 3.x branch (commit 9b0f0a713695fe074afe75ed968aafb046efefe8).

I discovered this bug while trying to compile and run GDNative with threads on web. But the issue remains even if you compile the Hello world project as explained in the book. Original discussion took place in "GDNative Threads on Web" thread on Discord server.

Somewhat related: #305

necrashter avatar Jan 31 '23 10:01 necrashter

Workaround: As @chitoyuu recommended on Discord, adding this setting to project's Cargo.toml reduces the .wasm binary size to 13.8 MB, which allows the game to run on both browsers:

[profile.dev]
opt-level = 1

If you have a workspace, you need to add this to workspace's Cargo.toml. Otherwise it will be ignored.

This also confirms that it's caused by large .wasm binary size.

necrashter avatar Jan 31 '23 10:01 necrashter