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