floooh / sokol-zig

Zig bindings for the sokol headers (https://github.com/floooh/sokol)
zlib License
341 stars 46 forks source link

add SAFE_HEAP=1 and STACK_OVERFLOW_CHECK=1 for Emscripten Debug builds #56

Closed silbinarywolf closed 6 months ago

silbinarywolf commented 6 months ago

I've found adding these has helped me debug and actually understand why my Emscripten application was randomly crashing.

For example, I was loading an image with the Zigimg package and the errors in my Chrome/Firefox DevTools would just say segmentation fault without pointing at a clear reason for the crash.

With -sSTACK_OVERFLOW_CHECK=1, I was able to instead get the following message and realize that I needed to bump my stack size.

index.js:9219 Stack overflow detected.  You can try increasing -sSTACK_SIZE (currently set to 65536)
floooh commented 6 months ago

Thanks for the PR! I'm not sure what performance implications those have (e.g. even though it's only in debug, more complex programs may become 'too slow' with those settings).

If it becomes too slow we might want to make those settings configurable via EmLinkOptions, but I think for now at least it makes sense to merge it as is.

The current Zig nightly has pretty severe breakge unfortunately (installing packages from github doesn't work - that's why the CI fails, and the wasm32-emscripten target seems to be broken, I get an error root struct of file 'os.wasi' has no member named 'E' (I'll merge the PR anyways, since the change is trivial).