Skip to content
Tech News
← Back to articles

Ported my C game to WASM, here's every bug that I hit

read original get WebAssembly Debugging Toolkit → more articles
Why This Matters

Porting a C game to WebAssembly revealed critical platform-specific challenges, especially related to pointer sizes and data serialization. Addressing these issues is essential for developers aiming for seamless cross-platform compatibility, ensuring their games run correctly in the 32-bit environment of the web. This highlights the importance of understanding platform differences when porting native applications to web technologies.

Key Takeaways

I wrote a game in plain C with a custom engine (bgfx, SDL2, miniaudio, cimgui) and recently ported it to web via Emscripten. Its live on itchio now. Here’s everything non-obvious that I ran into, hopefully saves someone some pain.

0. Had to go back to Visual Studio. Ugh.

I use RemedyBG as my daily debugger and its great, but it doesnt support 32-bit processes. Since WASM is 32-bit, I needed a 32-bit native build to reproduce bugs locally, which meant firing up Visual Studio again.

Turns out you don’t need a solution file. Just run:

devenv build\main.exe

and before you build, add vcvars32 to your build process

call "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars32.bat"

On VS, just Hit F5 or F11 and it runs the exe directly. No sln file needed, works fine for stepping through code and catching crashes. Not ideal but got the job done.

1. Web is 32-bit. Your 64-bit structs will break.

This was the root cause of most of my bugs. WASM is 32-bit address space, pointers are 4 bytes not 8. I was serializing asset structs directly to disk (pak file) that had raw pointers in them:

... continue reading