You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
3d Raylib game locks up after 5-15 seconds when running WebAssembly build. Sometimes I notice printed text on the screen becomes garbled. (Top line of text becomes ????????????????????????????????????)
I assumed the issue was something to do with extern struct types mixing with Zig struct types because replacing player_start_position: rl.Vector3 = rl.Vector3.init(0, 0, 0) with my own vector type seemed to fix the issue, but when I tried putting together a minimal code example, I couldn't reproduce the issue.
This issue does not occur when doing a Debug WASM build.
Run the game in either Chrome or Firefox, it happens on both.
Chrome / Firefox Logs
Game ends up spamming console logs with "index.wasm:0x2ece5 Uncaught RuntimeError: memory access out of bounds"
Pointing at the line i32.store offset=28 below"
if
global.get $global0
i32.const 32
i32.sub
local.tee $var10
global.set $global0
local.get $var10
i32.const 203572
i32.load
i32.store offset=28 // <- Error points at this line of wasm
local.get $var0
i32.eqz
local.set $var4
end
Expected Behavior
I expect the WASM build to not lock up or randomly corrupt a text drawn on string. If I am doing something wrong here, I feel like at most the game should just crash/lock up, not stomp over something else.
The text was updated successfully, but these errors were encountered:
silbinarywolf
changed the title
memory corruption issue can only reproduce on Wasm
memory corruption issue can only reproduce on Wasm -Doptimize=ReleaseSafe
Oct 15, 2023
I'm wondering if this issue I raised might be related to the first line item from this issue here: #10836 (comment)
ie. I had to put this in my main.zig for a project that uses SDL2 to avoid memory corruption issues, My guess is because you're not allocating with Emscriptens malloc, you end up stomping over things allocated with C libraries.
// Force allocator to use c allocator for emscripten// NOTE: This logic assumes you're using the workaround used here: https://github.com/Not-Nik/raylib-zig/blob/183347adaf8fb6dddf25ece3c8a157c8bab212c5/build.zig#L355pubconstos=if ( builtin.os.tag!=.wasi) std.oselsestruct {
pubconstheap=struct {
pubconstpage_allocator=std.heap.c_allocator;
};
};
Uh oh!
There was an error while loading. Please reload this page.
Zig Version
0.12.0-dev.668+c07d6e4c1
Targets tested on
Opening
3d Raylib game locks up after 5-15 seconds when running WebAssembly build. Sometimes I notice printed text on the screen becomes garbled. (Top line of text becomes ????????????????????????????????????)
I assumed the issue was something to do with extern struct types mixing with Zig struct types because replacing
player_start_position: rl.Vector3 = rl.Vector3.init(0, 0, 0)
with my own vector type seemed to fix the issue, but when I tried putting together a minimal code example, I couldn't reproduce the issue.This issue does not occur when doing a Debug WASM build.
Link to code
Because I couldn't create recreate the issue, I've opted for the next thing which is to just upload the whole project as-is here:
https://github.com/silbinarywolf/3d-raylib-toy-project
Steps to Reproduce and Observed Behavior
To reproduce, follow the steps here to get the Emscripten SDK if you don't have it already:
https://github.com/Not-Nik/raylib-zig#exporting-for-web
To build this, do the following:
Chrome / Firefox Logs
Game ends up spamming console logs with "index.wasm:0x2ece5 Uncaught RuntimeError: memory access out of bounds"
Pointing at the line
i32.store offset=28
below"Expected Behavior
I expect the WASM build to not lock up or randomly corrupt a text drawn on string. If I am doing something wrong here, I feel like at most the game should just crash/lock up, not stomp over something else.
The text was updated successfully, but these errors were encountered: