floooh / sokol-zig

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

Shapes example won't work in Firefox #82

Closed yanfrimmel closed 2 months ago

yanfrimmel commented 2 months ago

Error when running: zig build run-shapes -Dtarget=wasm32-emscripten

Error details:

Uncaught RuntimeError: unreachable executed tick http://localhost:6931/shapes.js:1725 In the function 'if' statement:

var _emscripten_request_animation_frame_loop = (cb, userData) => {
  function tick(timeStamp) {
    if (getWasmTableEntry(cb)(timeStamp, userData)) {
      requestAnimationFrame(tick);
    }
  }
  return requestAnimationFrame(tick);
};
yanfrimmel commented 2 months ago

The problem is in these lines:

var vertices: [6 * 1024]sshape.Vertex = undefined;
var indices: [16 * 1024]u16 = undefined;

Those arrays are too large, that causes segmentation fault, consider using heap allocations.

floooh commented 2 months ago

Ah, the Emscripten stack size reduction strikes again :/ (a little while ago, Emscripten reduced the default stack size to 64 KBytes).

I fixed the problem like this instead:

https://github.com/floooh/sokol-zig/commit/c5bdb504ea562eaa2c7d8c655e20467a1e385e3a

PS: thanks for taking the time to write the ticket, much appreciated :)