Fix the audio stall that breaks the title at +0x4dcbc9d (frame 82) #211

Manually merged
github merged 1 commit from github-bot/gh-211 into gh-pr/211/base 2026-12-05 22:43:34 +00:00 AGit
Owner

@⁠ktaylor9200 on GitHub · 2026-12-05 21:30 UTC · original
ktaylor9200:fix/audio-mix-lock-leak-upstream → main · +176 −0 · 4 files · 1 commits · merged 2026-12-05 21:40 UTC

What this fixes

exit -2147483645 (0x80000003) at larp-image-b99f876b74d4a77f.dll+0x4dcbc9d, about 15 s after launch, Frame: 82 in the game's crash log. Registers at the break: rax = 0x17fb0, rbx = 0x50, rsi = r8 = 0x6c0.

That int3 is the overflow check in the game's audio command-buffer write. The game thread appends a 1,728-byte block of audio effect commands to a double buffer every tick, and the audio engine's update is supposed to empty it. Here the update never ran, so the buffer filled up.

Root cause (a latent bug in the game)

  1. When the game cannot set up the default playback device, its audio engine goes on without an output (engine+0x3cdf9 = 1, stream manager +0x52c = 0 streams). The setup is the endpoint enumeration, ISpatialAudioClient and its render stream, all of which go to the host's COM.
  2. Every engine update ends with the mix, title+0x5267720 (engine vtable +0x80). It takes the stream manager's lock, and when there are no streams it returns at title+0x5267747 (je to a plain epilogue and ret) without unlocking.
  3. The job worker that ran the update keeps the lock forever. The audio thread (title+0x1e95040) blocks on it in its next pass (title+0x5594650 → lock), nothing drains the buffers, and the game breaks.

Seen live: the lock's owner is an idle job worker, with 3 waiters and recursion 1; the audio thread is blocked in the lock; the stream manager has 0 outputs and 0 streams. On a console the device setup does not fail, so this path is never reached.

The fix

All of it is in the build's hook table (larp_game::hooks::AudioMixUnlock), with the image's bytes checked before anything is placed:

  • Lock leak: the early return's je (0F 84 AE 05 00 00 at title+0x5267747) is pointed at the function's own unlocking exit (title+0x5267c7f: mov rcx, rdi, the same epilogue, vzeroupper, jmp unlock). The new bytes are 0F 84 32 05 00 00. The stack frame and rdi (the manager) are as that exit expects, and the recursive lock's count stays balanced.
  • Warning: an entry hook on aud_engine_set_no_output_q (title+0x5a65430, vtable +0x10) logs once when the game gives up on an audio output, and logs at info when it has one again.
  • Docs: a troubleshooting entry for +0x4dcbc9d.

With the fix the game keeps running instead of breaking. While it has no output it is silent, and the log says so. Whether sound comes back is up to the game: its device-recovery thread re-runs the setup on a device change.

Testing

On the b99f876b74d4a77f build, Windows 11, RTX 5080:

  • Fault injection, stream count: setting the stream manager's stream count to 0 for 300 ms while the game ran.
    • Unpatched: lock held by a job worker, 3 waiters, audio thread blocked. This is identical to the original crashes.
    • Patched: lock free, audio thread running.
  • Fault injection, endpoint count: setting the engine's endpoint count to 0 puts the game into its no-output mode. The warning is logged once, and the game keeps running.
  • Full run, this branch (upstream main 5a1a042 + the fix): ran until pipelines: every queued one is made, the title gets its input (60,621 pipelines), then 2 more minutes. No crash; frame 5,890 at the end; the command buffers never held more than one record.
  • Full run, the same commit on v1.1.0: the same result (frame 11,537 at the end).
  • Unit test: the retargeted jump's encoding.

On the PC where this was seen, the device setup failed only on the first runs, while the default playback device had never had its spatial sound set. After it was set once (Windows Sonic for Headphones, then Off again) the setup succeeded every time, so the natural failure could not be reproduced afterwards. Which step of the setup failed is not known.

🤖 Generated with Claude Code

**@⁠ktaylor9200** on GitHub · 2026-12-05 21:30 UTC · [original](https://github.com/gamingwithhomie/larp/pull/211) `ktaylor9200:fix/audio-mix-lock-leak-upstream` → `main` · +176 −0 · 4 files · 1 commits · merged 2026-12-05 21:40 UTC ## What this fixes `exit -2147483645` (`0x80000003`) at `larp-image-b99f876b74d4a77f.dll+0x4dcbc9d`, about 15 s after launch, `Frame: 82` in the game's crash log. Registers at the break: `rax = 0x17fb0`, `rbx = 0x50`, `rsi = r8 = 0x6c0`. That `int3` is the overflow check in the game's audio command-buffer write. The game thread appends a 1,728-byte block of audio effect commands to a double buffer every tick, and the audio engine's update is supposed to empty it. Here the update never ran, so the buffer filled up. ## Root cause (a latent bug in the game) 1. When the game cannot set up the default playback device, its audio engine goes on without an output (`engine+0x3cdf9 = 1`, stream manager `+0x52c = 0` streams). The setup is the endpoint enumeration, `ISpatialAudioClient` and its render stream, all of which go to the host's COM. 2. Every engine update ends with the mix, `title+0x5267720` (engine vtable `+0x80`). It takes the stream manager's lock, and when there are no streams it returns at `title+0x5267747` (`je` to a plain epilogue and `ret`) **without unlocking**. 3. The job worker that ran the update keeps the lock forever. The audio thread (`title+0x1e95040`) blocks on it in its next pass (`title+0x5594650` → lock), nothing drains the buffers, and the game breaks. Seen live: the lock's owner is an idle job worker, with 3 waiters and recursion 1; the audio thread is blocked in the lock; the stream manager has 0 outputs and 0 streams. On a console the device setup does not fail, so this path is never reached. ## The fix All of it is in the build's hook table (`larp_game::hooks::AudioMixUnlock`), with the image's bytes checked before anything is placed: - **Lock leak:** the early return's `je` (`0F 84 AE 05 00 00` at `title+0x5267747`) is pointed at the function's own unlocking exit (`title+0x5267c7f`: `mov rcx, rdi`, the same epilogue, `vzeroupper`, `jmp unlock`). The new bytes are `0F 84 32 05 00 00`. The stack frame and `rdi` (the manager) are as that exit expects, and the recursive lock's count stays balanced. - **Warning:** an entry hook on `aud_engine_set_no_output_q` (`title+0x5a65430`, vtable `+0x10`) logs once when the game gives up on an audio output, and logs at info when it has one again. - **Docs:** a troubleshooting entry for `+0x4dcbc9d`. With the fix the game keeps running instead of breaking. While it has no output it is silent, and the log says so. Whether sound comes back is up to the game: its device-recovery thread re-runs the setup on a device change. ## Testing On the `b99f876b74d4a77f` build, Windows 11, RTX 5080: - **Fault injection, stream count:** setting the stream manager's stream count to 0 for 300 ms while the game ran. - Unpatched: lock held by a job worker, 3 waiters, audio thread blocked. This is identical to the original crashes. - Patched: lock free, audio thread running. - **Fault injection, endpoint count:** setting the engine's endpoint count to 0 puts the game into its no-output mode. The warning is logged once, and the game keeps running. - **Full run, this branch (upstream `main` 5a1a042 + the fix):** ran until `pipelines: every queued one is made, the title gets its input` (60,621 pipelines), then 2 more minutes. No crash; frame 5,890 at the end; the command buffers never held more than one record. - **Full run, the same commit on v1.1.0:** the same result (frame 11,537 at the end). - **Unit test:** the retargeted jump's encoding. On the PC where this was seen, the device setup failed only on the first runs, while the default playback device had never had its spatial sound set. After it was set once (Windows Sonic for Headphones, then Off again) the setup succeeded every time, so the natural failure could not be reproduced afterwards. Which step of the setup failed is not known. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
When the title cannot set up the default playback device (its endpoint
enumeration, ISpatialAudioClient and render stream are the host's own
COM), its audio engine goes on without an output. In that mode the mix
that every engine update ends with, aud_mix_output_streams_q
(title+0x5267720), takes the stream manager's lock and returns without
giving it back when the manager has no output stream (the je at
title+0x5267747 skips the unlock). The job worker that ran the update
keeps the lock, the audio thread blocks on it in its next pass, nothing
empties the effect command buffers the game thread fills every tick, and
the title breaks in its command buffer write (title+0x4dcbc9d) when one
is full, about 15 s in.

Point that early return at the function's own unlocking exit
(title+0x5267c7f), whose frame and epilogue are the same but for the
unlock, so the title keeps running (without sound) until the device
changes. Hook aud_engine_set_no_output_q (title+0x5a65430) to say when
the title gives up on an output and when it has one again. Both are in
the build's hook table (larp_game::hooks::AudioMixUnlock), checked
against the image's bytes before they are placed.

Verified on the build b99f876b74d4a77f: with the manager's stream count
forced to 0 for 300 ms, an unpatched larp leaves the lock held by a job
worker and the audio thread blocked (as in the original crashes), and a
patched one keeps the lock free and the audio running. Forcing the
endpoint count to 0 puts the title in its mode without an output, the
warning is logged once, and the game keeps running. Normal runs drain
the buffers as before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-05 21:34:17 +00:00
github-bot changed target branch from main to gh-pr/211/base 2026-12-05 21:48:56 +00:00
github-bot referenced this pull request from a commit 2026-12-05 22:43:29 +00:00
github manually merged commit 1822959524 into gh-pr/211/base 2026-12-05 22:43:34 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.