惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

J
Java Code Geeks
Stack Overflow Blog
Stack Overflow Blog
B
Blog RSS Feed
C
Check Point Blog
D
Docker
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
Google DeepMind News
Google DeepMind News
MongoDB | Blog
MongoDB | Blog
博客园_首页
Apple Machine Learning Research
Apple Machine Learning Research
量子位
有赞技术团队
有赞技术团队
IT之家
IT之家
大猫的无限游戏
大猫的无限游戏
D
DataBreaches.Net
M
MIT News - Artificial intelligence
B
Blog
阮一峰的网络日志
阮一峰的网络日志
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
腾讯CDC
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
V
V2EX
月光博客
月光博客

Hacker News

GitHub - SeanFDZ/macmind: Single-layer transformer in HyperTalk for the classic Macintosh Show HN: Agent-cache – Multi-tier LLM/tool/session caching for Valkey and Redis Bonsai 1-bit WebGPU - a Hugging Face Space by webml-community Moving a large-scale metrics pipeline from StatsD to OpenTelemetry / Prometheus GitHub - Nightmare-Eclipse/RedSun: The Red Sun vulnerability repository GitHub - SethPyle376/hiraeth: Local AWS emulator focused on fast integration testing, with SQS support, SQLite-backed state, and a debug-friendly web UI. GitHub - macOS26/Agent: Any AI, replaces Claude Code, Cursor, OpenClaw. Over 18 LLM providers (Claude, OpenAI, Gemini, Ollama, Zai, HF, Qwen) wired into a native Mac app that writes code, builds Xcode projects, bumps versions, manages git, automates Safari, use AppleScript, JS or Accessibility, extend Agent! w/ MCP Servers, run tasks from your iPhone via Messages. YouTube now lets you turn off Shorts I Made a Terminal Pager Burgers | マクドナルド公式 Commands — HackerNews CLI documentation ChatGPT for Excel PiCore - Raspberry Pi Port of Tiny Core Linux Live Nation illegally monopolized ticketing market, jury finds Google Broke Its Promise to Me. Now ICE Has My Data. Founding Engineer at Adaptional | Y Combinator CRISPR takes important step toward silencing Down syndrome’s extra chromosome GitHub - saffron-health/libretto: The AI toolkit for building reliable browser automations US v. Heppner (S.D.N.Y. 2026) no attorney-client privilege for AI chats [pdf] Retrofitting JIT Compilers into C Interpreters IPv6 – Google The Accursèd Alphabetical Clock Cybersecurity Looks Like Proof of Work Now Fragments: April 14 Cal.com Goes Closed Source: Why AI Security Is Forcing Our Decision | Cal.com - Scheduling Software for Online Bookings Laravel raised money and now injects ads directly into your agent When moving fast, talking is the first thing to break Too much Discussion of the XOR swap trick – Heather Cafe Introduction to Spherical Harmonics for Graphics Programmers The Grand Line
Porting Match Morphosis To WASM | ernesernesto io
2026-06-13 · via Hacker News

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:

typedef struct AssetSprite {
    u32 width, height;
    u8* dataBytes;  // 8 bytes on 64-bit, 4 bytes on WASM
    i32 dataSize;
} AssetSprite;

When I packed assets on 64-bit Windows and loaded them on WASM, the struct layout was completely different. sizeof(Assets) was 26328 on native and 25556 on web. Every field after the first pointer was at the wrong offset, so all texture and shader data came out as garbage.

In hindsight this is probably obvious to anyone who builds cross platform regularly, but I havent built 32-bit in years so I tripped on the pointer size thing.

Fix: I separated runtime data from baking data entirely. Instead of a pointer living inside the asset struct, I now have a flat array on the side:

AssetDataBytes assetData[TOTAL_ASSET_COUNT];
i32 assetDataId;

typedef struct AssetDataBytes {
    u8* data;
    i32 size;
} AssetDataBytes;

Every time I add a new asset during baking, just bump assetDataId and write the bytes there. The serialized asset struct has no pointers at all, so layout is identical on 32 and 64-bit. Packer is single threaded and still finishes under 3 seconds for the whole game, good enough for my use case since asset count is relatively small.

2. Debug in 32-bit native, not the browser

This was the biggest productivity unlock honestly. Since 32-bit native has the same struct sizes as WASM, bugs that only appeared on web also appeared on 32-bit native, where I had real breakpoints, memory watch, and call stacks.

For actually hunting the bugs I used a combination of /fsanitize=address when compiling plus data breakpoints. Trigger the bug, ASan will catch the bad access. Data breakpoint would also tells you exactly what wrote to that address. Makes what would be a multi hour hunt into something you can solve pretty quickly. Dont try to debug WASM crashes from the browser console alone since its painful and slow.

3. A bug that was silently correct on 64-bit

typedef struct ThingHandle {
    i32 id;
    i32 generation;
} ThingHandle;

// wrong
game->boardPieces = swAlloc(sizeof(ThingHandle*) * row * column);

// correct
game->boardPieces = swAlloc(sizeof(ThingHandle) * row * column);

On 64-bit, sizeof(ThingHandle*) is 8, which happens to be the same as sizeof(ThingHandle). So the wrong code allocated exactly the right amount of memory by coincidence and worked fine for a while. On 32-bit WASM, sizeof(ThingHandle*) is 4, so it allocated half the memory it needed and corrupted whatever came after it. Pretty classic mixup, just hidden for a long time by 64-bit making them accidentally equal.

4. OpenGL ES (WebGL) is way stricter than Direct3D

bgfx uses Direct3D on Windows and OpenGL ES on web. A bunch of things I got away with on D3D broke hard on WebGL:

Vertex layout renderer type: I was passing BGFX_RENDERER_TYPE_NOOP to bgfx_vertex_layout_begin. Works on D3D, broken on OpenGL because it cant assign correct attribute locations. Use bgfx_get_renderer_type() instead.

Component count mismatch: I had COLOR1 declared as 2 components in the layout but the shader used vec4. D3D ignores the mismatch. OpenGL ES throws a fatal every frame. Component counts must exactly match what the shader declares.

Framebuffer Y flip - OpenGL has Y=0 at the bottom, D3D has Y=0 at the top. My fullscreen blit was upside down on web. Fixed by flipping UV V coordinates in the final render target texture blit.

5. Shaders need recompiling for GLSL ES

bgfx’s shaderc compiles for specific backends. My shaders were HLSL compiled for DirectX. On web I needed GLSL ES, profile flag changes from -p s_5_0 to -p 300_es.

Two things that tripped me up:

  • lerp() is HLSL only. GLSL uses mix(). bgfx’s bgfx_shader.sh already defines mix as a cross platform macro so just use that everywhere and both platforms work.
  • GLSL ES is strict about integer vs float. Passing 0 or 1 to a float parameter is a compile error. Has to be 0.0 and 1.0.

6. Web Audio autoplay + a weird Emscripten exports issue

Google has implemented a policy in their browsers that prevent automatic media output without first receiving some kind of user input. Miniaudio handles this internally by registering click and touchend listeners that resume the AudioContext automatically. I spend too much time trying to make miniaudio web build works messing around with a lot of it’s flags AUDIO_WORKLET, WASM_WORKERS, ASYNCIFY. Even trying to make a different initialization path between web & native, the web init after the first touch, but it still not working, there’s still an error throws on the js console when the AudioContext initialized.

Turns out newer versions of Emscripten seem to remove some runtime exports by default. miniaudio needs HEAPF32 to be available from JS side and it wasnt. Had to explicitly add it:

-s EXPORTED_RUNTIME_METHODS="['ccall','cwrap','HEAPF32']"

Not sure if this is a newer Emscripten behavior or a combination of my flags, couldn’t find anything on google about it, might save someone an hour of head scratching. All things considered, miniaudio really get the job done, nothing need to be initialized differently between native and web

Final thoughts

Genuinely happy with how it turned out, I spent a weekend on this port and honestly expected it to take longer. Writing a custom C engine, porting it to web, having the game load fast and play instantly with no Unity or Godot baggage, that feels really good.

The Emscripten toolchain is solid. Most of the pain came from things that worked by accident on Windows that the web holds you accountable for. Once you know what to look for, fixing them is pretty straightforward.

Game is live https://zhongda8.itch.io/matchmorphosis

And you can wishlist it https://store.steampowered.com/app/4131100/Match_Morphosis

Thanks for reading!