Running dvui + sdl3 on WEB

I successfully run SDL with embedded dvui on WEB. Project link https://codeberg.org/knightpp/game-of-life-zig and you can play here https://knightpp.codeberg.page/game-of-life-zig/@pages/.

SDL3 supports callbacks style, so you don’t have to change a lot of code to port your app to a new platform. And it works! After I setup build.zig and added some tweaks to fix dvui’s compilation, my app run on WEB relatively easy!

Though it took a lot of time to get there. Turns out LTO breaks generated wasm really badly, it still loaded and displayed something but was half functional.

Miscompilations? I had something like this

const new_game = try Game.init(...);
state.game.deinit()
state.game = new_game;

But for some reason it worked fine on x86_64-linux but not on wasm-emscripten target. By pure luck I could track down the issue really quickly.

5 Likes

That is very cool! I did not know that you could run sdl3 on top of emscripten, way to go!

1 Like