fix(audio): SDL starts each subsystem once, so the microphone's stream is never freed under the game #3228

Merged
HumanBean merged 2 commits from cuecuemoar/Longshot:fix/mic-sdl-init-once into main 2026-12-05 17:17:42 +00:00
Contributor

Summary

With a microphone chosen by name in the Insert menu (Audio, Microphone), the game crashed after a while of play, inside SDL3.dll (SDL_GetAudioStreamAvailable): #1524, #1928, #2310 and #2498, the last through the menu's Test microphone. The workaround so far was Microphone: Off.

Cause. SDL counts each subsystem's starts in 8 bits (static Uint8 SDL_SubsystemRefCount[32] in SDL's src/SDL.c, in SDL 3.4.20 and SDL2 2.32 alike). Its only overflow check is an SDL_assert, which isn't in a release build.

  • hos_sdl_init asked SDL for a start every time it was called, and rec_ready calls it on every hos_sdl_mic_list and hos_sdl_mic_open.
  • A microphone chosen by name is looked up again every 5 s (host/nn_audio_in.c pump, CHECK_NS), and each Insert menu open lists the microphones once more.
  • So every 256th call wrapped the count to 0. The next one ran SDL_InitAudio, which calls SDL_QuitAudio because a driver is up, and that destroys every stream opened with SDL_OpenAudioDeviceStream, the microphone's included.
  • The game went on reading the freed stream. That is one wrap about every 21 minutes, and a crash once the memory is reused, which fits the reports' hours of play. All four reports had a microphone chosen by name.

This changes hos_sdl_init (host/hos_sdl.c, read it first) to remember the subsystems it has started and ask SDL only for the others. A failed start is still tried again. It runs under a lock, because SDL_InitSubSystem isn't safe from two threads, and the microphones and the sound's output can ask for the first time together. Nothing in Longshot stops an SDL subsystem (no SDL_Quit or SDL_QuitSubSystem), so once started is started for the run. The pads' and the window's single starts go through the same function, unchanged in effect.

To see it on main: choose a microphone by name in Audio, Microphone, and leave Test microphone running for about 22 minutes. Opening and closing the Insert menu about 250 times first gets there in about a minute. The game crashes in SDL3.dll.

Fixes #1524. Fixes #1928. Fixes #2310. Fixes #2498.

Testing

Tested:

  • Game run: Windows 10, RTX 4090, the Logitech C922's microphone, headless runs through the job queue, main 3a0f7d8f7 against this PR 476f38a51 built the same way. The run used the title screen and kokiri-start's test profile.
    • First RX_VK_MENU_SCRIPT opened and closed the Insert menu 240 times, each open listing the microphones.
    • Then, over the bridge, option set microphone 2 (read back as Microphone (C922 Pro Stream Webcam)), and Test microphone started with the menu left open.
    • main: audio in: Microphone (C922 Pro Stream Webcam) open (48000 Hz, 1 channel), then about 70 s later CRASH: exception 0xc0000005 (read 0xd) at SDL3.dll+0x11b625. The crash record reads thread: host, module_offset: SDL3.dll+0x11b625, uptime_s: 284, and the game exited with code 5. SDL3.dll+0x11b625 is the offset in #1928's and #2310's reports.
    • This PR: the same steps, and the test ran 602 s with the meter still reading (Testing: 1% in the last shot). No crash record, exit code 0.
  • Checks:
    • tests/test_sdl_init_once.py (new) cuts the real hos_sdl_init, rec_ready and hos_sdl_mic_list and runs them with a fake SDL3 that counts as SDL does: 8 bits, sound restarted at 0. It lists the microphones 600 times with a stream open.
      • On main: FAIL: list 257 restarted SDL's sound (2 starts, 1 quits): the microphone's stream was freed (gcc and clang).
      • Here: PASS (gcc and clang).
      • Undoing the fix's started |= want makes it fail again.
    • tests/test_headless_sigterm.py cuts the same function: its fixture gets the lock's stand-ins, and its placeholders now match whole lines, because SRWLOCK_INIT held the word INIT it replaced. Its ten cases still pass.
    • The other checks that read hos_sdl.c or nn_audio_in.c pass: test_microphone_test_gain, test_audio_in, test_pad_appcontainer, test_builder_pads_route, test_display_pointer.
    • Host code compiles on Linux and for Windows with llvm-mingw (scripts/check_host_compile.py), head and main.
    • The strict suite on Linux, this PR against main 3a0f7d8f7: 846 passed, 53 failed, 13 skipped here, against 845, 53 and 13 on main. The 53 are the same files on both, listed below.
  • A second agent reviewed the diff and the test cold. It found nothing blocking; its one point, the first-call race, is the lock.

Still to test:

  • Linux, any GPU: choose a microphone by name and leave Test microphone running 25 minutes, or open the Insert menu 260 times and then start the test. Expect no crash, the meter still moving, and the game's own sound still playing; on Linux the game's sound is an SDL stream too, so main would also cut it. (@Beanstalk, or by hand)
  • Windows, by hand: an hour of play with Microphone set to a named microphone, playing the ocarina with it now and then. Expect no crash and the microphone still heard.
The 53 files that fail on main too (this WSL setup, strict)

tests/f2i_immediate tests/global_load_16 tests/native_suatom tests/test_cloth_kernels.py tests/test_cloth_loops.py tests/test_cloth_step8.py tests/test_coop_spirv.py tests/test_curve_pass.py tests/test_dead_targets_sweep.py tests/test_default_point_size.py tests/test_depth_sample_types.py tests/test_dev_update.py tests/test_dlssg.py tests/test_draw_parameters.py tests/test_drawn_page_map.py tests/test_fsr4_tune.py tests/test_image_arrays.py tests/test_image_view_retry.py tests/test_lens_eye_pass.py tests/test_lifter.py tests/test_lower_depbar.py tests/test_lower_lds_after_sts.py tests/test_lower_register_markers.py tests/test_menu_hooks.py tests/test_mesh_fallback_capacity.py tests/test_mesh_fallback_layout.py tests/test_mesh_first_types.py tests/test_mesh_unreachable_outputs.py tests/test_native_suatom.py tests/test_no_game_title.py tests/test_no_map_reload.py tests/test_nonuniform_image_arrays.py tests/test_present_acquire_ahead.py tests/test_present_geometry_trace.py tests/test_present_held_image.py tests/test_present_image_free.py tests/test_prof_clock.py tests/test_program_answer_domains.py tests/test_reshade_fx.py tests/test_sim_turf_pools.py tests/test_spirv_struct_identity.py tests/test_sync_watch_event.py tests/test_target_pool_cap.py tests/test_target_retention.py tests/test_tex_desc_memo.py tests/test_texture_phi_dominance.py tests/test_thinlto_tls.py tests/test_turf_budget.py tests/test_ui_renderer.py tests/test_unsigned_image_types.py tests/test_vk_draw_overhead_lean.py tests/test_vk_tex_btree_get_fast.py tests/test_wmma16_spirv_val.py

Measurements

Verdict: the crash is gone. On main, the same steps crash in SDL3.dll about 70 s after Test microphone starts; with this PR the test runs 602 s without one. There is nothing to time: hos_sdl_init runs a few times a minute at most, and now asks SDL less often.

Setup: Windows 10, RTX 4090, the C922's microphone chosen by name; headless on the title screen, 240 Insert menu opens, then Test microphone (Testing above).

Before: main @ 3a0f7d8f7 After: this PR @ 476f38a51
test_sdl_init_once.py (gcc, clang) FAIL at list 257: the stream freed PASS: sound started once in 601 lists
Game, named microphone + Test microphone after 240 menu opens crash at SDL3.dll+0x11b625, about 70 s in 602 s, no crash, meter reading

Risks

  • An SDL subsystem is started once per run. If SDL ever failed in a way that a second SDL_InitSubSystem used to repair, it no longer gets that call. Nothing in the tree relies on that: the sound's output already started once (playback_initialized), and the pads and window start once at start-up. A failed start is still retried.
  • Turning it off: a revert is enough. Nothing changes in saves, longshot_options.ini or the caches.
  • #3116 (the audio broker, WIP) moves the microphone into the builder, which starts SDL once. This keeps the in-game path safe, which stays as its fallback and is main's only path today. The two touch different lines of hos_sdl.c.

Checklist

Ready for review

  • One topic, on current main; the title is a Conventional Commit.
  • Tested on my own PC, in the game for a change the game runs, as Testing says.
  • mise run test passes (any failure that also fails on main is named).
  • Measured against main, or Measurements says why there is nothing to measure.
  • No game files, build output or hand-edited generated files; third_party/ untouched; nothing GPL-incompatible.

When it applies

  • A fix: a game-free test that fails on main and passes here.
  • A check under tests/ that reads changed source is updated, not weakened.
  • Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths.
  • AI assistance recorded with Assisted-by: / Co-Authored-By: trailers.

Ready to merge

  • Everything in Still to test has run, its results in Tested.
  • Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers").
  • Approved in review, every comment answered.
  • CI passes on the head; on current main, measured again or a comment says why the numbers still hold.

🤖 Generated with Claude Code

https://claude.ai/code/session_01VxeaZjFD5sZgue2tRx5H5v

## Summary With a microphone chosen by name in the Insert menu (Audio, Microphone), the game crashed after a while of play, inside SDL3.dll (`SDL_GetAudioStreamAvailable`): #1524, #1928, #2310 and #2498, the last through the menu's Test microphone. The workaround so far was Microphone: Off. **Cause.** SDL counts each subsystem's starts in 8 bits (`static Uint8 SDL_SubsystemRefCount[32]` in SDL's `src/SDL.c`, in SDL 3.4.20 and SDL2 2.32 alike). Its only overflow check is an `SDL_assert`, which isn't in a release build. - `hos_sdl_init` asked SDL for a start every time it was called, and `rec_ready` calls it on every `hos_sdl_mic_list` and `hos_sdl_mic_open`. - A microphone chosen by name is looked up again every 5 s (`host/nn_audio_in.c` `pump`, `CHECK_NS`), and each Insert menu open lists the microphones once more. - So every 256th call wrapped the count to 0. The next one ran `SDL_InitAudio`, which calls `SDL_QuitAudio` because a driver is up, and that destroys every stream opened with `SDL_OpenAudioDeviceStream`, the microphone's included. - The game went on reading the freed stream. That is one wrap about every 21 minutes, and a crash once the memory is reused, which fits the reports' hours of play. All four reports had a microphone chosen by name. **This changes** `hos_sdl_init` (`host/hos_sdl.c`, read it first) to remember the subsystems it has started and ask SDL only for the others. A failed start is still tried again. It runs under a lock, because `SDL_InitSubSystem` isn't safe from two threads, and the microphones and the sound's output can ask for the first time together. Nothing in Longshot stops an SDL subsystem (no `SDL_Quit` or `SDL_QuitSubSystem`), so once started is started for the run. The pads' and the window's single starts go through the same function, unchanged in effect. **To see it on main:** choose a microphone by name in Audio, Microphone, and leave Test microphone running for about 22 minutes. Opening and closing the Insert menu about 250 times first gets there in about a minute. The game crashes in SDL3.dll. Fixes #1524. Fixes #1928. Fixes #2310. Fixes #2498. ## Testing **Tested:** - **Game run:** Windows 10, RTX 4090, the Logitech C922's microphone, headless runs through the job queue, main 3a0f7d8f7 against this PR 476f38a51 built the same way. The run used the title screen and `kokiri-start`'s test profile. - First `RX_VK_MENU_SCRIPT` opened and closed the Insert menu 240 times, each open listing the microphones. - Then, over the bridge, `option set microphone 2` (read back as `Microphone (C922 Pro Stream Webcam)`), and Test microphone started with the menu left open. - **main:** `audio in: Microphone (C922 Pro Stream Webcam) open (48000 Hz, 1 channel)`, then about 70 s later `CRASH: exception 0xc0000005 (read 0xd) at SDL3.dll+0x11b625`. The crash record reads `thread: host`, `module_offset: SDL3.dll+0x11b625`, `uptime_s: 284`, and the game exited with code 5. `SDL3.dll+0x11b625` is the offset in #1928's and #2310's reports. - **This PR:** the same steps, and the test ran 602 s with the meter still reading (`Testing: 1%` in the last shot). No crash record, exit code 0. - **Checks:** - `tests/test_sdl_init_once.py` (new) cuts the real `hos_sdl_init`, `rec_ready` and `hos_sdl_mic_list` and runs them with a fake SDL3 that counts as SDL does: 8 bits, sound restarted at 0. It lists the microphones 600 times with a stream open. - On main: `FAIL: list 257 restarted SDL's sound (2 starts, 1 quits): the microphone's stream was freed` (gcc and clang). - Here: `PASS` (gcc and clang). - Undoing the fix's `started |= want` makes it fail again. - `tests/test_headless_sigterm.py` cuts the same function: its fixture gets the lock's stand-ins, and its placeholders now match whole lines, because `SRWLOCK_INIT` held the word `INIT` it replaced. Its ten cases still pass. - The other checks that read `hos_sdl.c` or `nn_audio_in.c` pass: test_microphone_test_gain, test_audio_in, test_pad_appcontainer, test_builder_pads_route, test_display_pointer. - Host code compiles on Linux and for Windows with llvm-mingw (`scripts/check_host_compile.py`), head and main. - The strict suite on Linux, this PR against main 3a0f7d8f7: 846 passed, 53 failed, 13 skipped here, against 845, 53 and 13 on main. The 53 are the same files on both, listed below. - A second agent reviewed the diff and the test cold. It found nothing blocking; its one point, the first-call race, is the lock. **Still to test:** - Linux, any GPU: choose a microphone by name and leave Test microphone running 25 minutes, or open the Insert menu 260 times and then start the test. Expect no crash, the meter still moving, and the game's own sound still playing; on Linux the game's sound is an SDL stream too, so main would also cut it. (@Beanstalk, or by hand) - Windows, by hand: an hour of play with Microphone set to a named microphone, playing the ocarina with it now and then. Expect no crash and the microphone still heard. <details><summary>The 53 files that fail on main too (this WSL setup, strict)</summary> tests/f2i_immediate tests/global_load_16 tests/native_suatom tests/test_cloth_kernels.py tests/test_cloth_loops.py tests/test_cloth_step8.py tests/test_coop_spirv.py tests/test_curve_pass.py tests/test_dead_targets_sweep.py tests/test_default_point_size.py tests/test_depth_sample_types.py tests/test_dev_update.py tests/test_dlssg.py tests/test_draw_parameters.py tests/test_drawn_page_map.py tests/test_fsr4_tune.py tests/test_image_arrays.py tests/test_image_view_retry.py tests/test_lens_eye_pass.py tests/test_lifter.py tests/test_lower_depbar.py tests/test_lower_lds_after_sts.py tests/test_lower_register_markers.py tests/test_menu_hooks.py tests/test_mesh_fallback_capacity.py tests/test_mesh_fallback_layout.py tests/test_mesh_first_types.py tests/test_mesh_unreachable_outputs.py tests/test_native_suatom.py tests/test_no_game_title.py tests/test_no_map_reload.py tests/test_nonuniform_image_arrays.py tests/test_present_acquire_ahead.py tests/test_present_geometry_trace.py tests/test_present_held_image.py tests/test_present_image_free.py tests/test_prof_clock.py tests/test_program_answer_domains.py tests/test_reshade_fx.py tests/test_sim_turf_pools.py tests/test_spirv_struct_identity.py tests/test_sync_watch_event.py tests/test_target_pool_cap.py tests/test_target_retention.py tests/test_tex_desc_memo.py tests/test_texture_phi_dominance.py tests/test_thinlto_tls.py tests/test_turf_budget.py tests/test_ui_renderer.py tests/test_unsigned_image_types.py tests/test_vk_draw_overhead_lean.py tests/test_vk_tex_btree_get_fast.py tests/test_wmma16_spirv_val.py </details> ## Measurements **Verdict:** the crash is gone. On main, the same steps crash in SDL3.dll about 70 s after Test microphone starts; with this PR the test runs 602 s without one. There is nothing to time: `hos_sdl_init` runs a few times a minute at most, and now asks SDL less often. Setup: Windows 10, RTX 4090, the C922's microphone chosen by name; headless on the title screen, 240 Insert menu opens, then Test microphone (Testing above). | | Before: main @ 3a0f7d8f7 | After: this PR @ 476f38a51 | |---|---|---| | `test_sdl_init_once.py` (gcc, clang) | FAIL at list 257: the stream freed | PASS: sound started once in 601 lists | | Game, named microphone + Test microphone after 240 menu opens | crash at SDL3.dll+0x11b625, about 70 s in | 602 s, no crash, meter reading | ## Risks - An SDL subsystem is started once per run. If SDL ever failed in a way that a second `SDL_InitSubSystem` used to repair, it no longer gets that call. Nothing in the tree relies on that: the sound's output already started once (`playback_initialized`), and the pads and window start once at start-up. A failed start is still retried. - Turning it off: a revert is enough. Nothing changes in saves, `longshot_options.ini` or the caches. - #3116 (the audio broker, WIP) moves the microphone into the builder, which starts SDL once. This keeps the in-game path safe, which stays as its fallback and is main's only path today. The two touch different lines of `hos_sdl.c`. ## Checklist ### Ready for review - [x] One topic, on current `main`; the title is a Conventional Commit. - [x] Tested on my own PC, in the game for a change the game runs, as Testing says. - [x] `mise run test` passes (any failure that also fails on `main` is named). - [x] Measured against `main`, or Measurements says why there is nothing to measure. - [x] No game files, build output or hand-edited generated files; `third_party/` untouched; nothing GPL-incompatible. ### When it applies - [x] A fix: a game-free test that fails on `main` and passes here. - [x] A check under `tests/` that reads changed source is updated, not weakened. - [x] Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths. - [x] AI assistance recorded with `Assisted-by:` / `Co-Authored-By:` trailers. ### Ready to merge - [ ] Everything in Still to test has run, its results in Tested. - [ ] Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers"). - [ ] Approved in review, every comment answered. - [ ] CI passes on the head; on current `main`, measured again or a comment says why the numbers still hold. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01VxeaZjFD5sZgue2tRx5H5v
SDL counts a subsystem's starts in 8 bits, and rec_ready starts sound on
every microphone list and open: the 256th wraps the count, the next start
runs SDL_QuitAudio and frees the open microphone stream. The check compiles
the real hos_sdl_init, rec_ready and hos_sdl_mic_list with a fake SDL3 that
counts as SDL does; on main the 257th list frees the stream.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01VxeaZjFD5sZgue2tRx5H5v
fix(audio): SDL starts each subsystem once, so the microphone's stream is never freed under the game (#1524)
Some checks are pending
CI / Host C for Windows (llvm-mingw, compile only) (pull_request) Blocked by required conditions
CI / Renderer build check (Windows, compile --only renderer, without and with FSR 4) (pull_request) Blocked by required conditions
CI / Renderer build check (Linux, compile --only renderer, without and with FSR 4) (pull_request) Blocked by required conditions
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Blocked by required conditions
CI / Game-free checks (run_all.py, part 2/2) (pull_request) Blocked by required conditions
CI / What the change needs (pull_request) Blocked by required conditions
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Blocked by required conditions
CI / Third-party parts and guide screenshots (pull_request) Blocked by required conditions
CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request) Blocked by required conditions
CI / Website build and checks (pull_request) Blocked by required conditions
PR description / Title and description (pull_request_target) Successful in 6s
476f38a513
SDL counts a subsystem's starts in 8 bits, and hos_sdl_init asked for a
start on every microphone list and open: a microphone chosen by name is
looked up every 5 s, so about every 21 minutes the count wrapped, the next
start ran SDL_QuitAudio, and the game went on reading the freed stream
(SDL_GetAudioStreamAvailable: #1524, #1928, #2310, #2498). hos_sdl_init now
keeps the subsystems it started and asks SDL only for the others, under a
lock (SDL_InitSubSystem is not safe from two threads); a failed start is
still tried again. test_headless_sigterm's fixture gets the lock's stand-ins,
its placeholders matched as whole lines (SRWLOCK_INIT held its INIT).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01VxeaZjFD5sZgue2tRx5H5v
Author
Contributor

Tested in game: Windows 10, RTX 4090, Logitech C922 microphone chosen by name; headless, title screen: 240 Insert menu opens, then Test microphone. main 3a0f7d8f7 crashed ~70 s in at SDL3.dll+0x11b625 (crash record, exit 5); this PR 476f38a51 ran the test 602 s with the meter reading, no crash, exit 0.

Tested in game: Windows 10, RTX 4090, Logitech C922 microphone chosen by name; headless, title screen: 240 Insert menu opens, then Test microphone. main 3a0f7d8f7 crashed ~70 s in at SDL3.dll+0x11b625 (crash record, exit 5); this PR 476f38a51 ran the test 602 s with the meter reading, no crash, exit 0.
cuecuemoar changed title from WIP: fix(audio): SDL starts each subsystem once, so the microphone's stream is never freed under the game to fix(audio): SDL starts each subsystem once, so the microphone's stream is never freed under the game 2026-12-05 03:58:18 +00:00
Owner
@review
BeanBot left a comment

Recommendation: Approve. The Windows reproduction supports the fix: the base crashed after repeated microphone listings, while this head kept the meter running for 602 seconds. Linux audio and the requested Windows gameplay run remain untested. Nothing blocking is left: what remains is for the author before merging (below). Recommend approval; not approved on the forge.

The change prevents repeated microphone enumeration from wrapping SDL’s subsystem reference count and destroying an active stream. It adds a lock and a game-free regression test; the added work is limited to subsystem initialization calls.

Should fix (1): not blocking, but worth doing before merging.

  • L1 tests/test_sdl_init_once.py:133: The new test treats the compiler setting as a single executable and defaults to gcc when run directly, so it does not fully honor CC. (more on the line) Do: Use the repository’s compiler_command and parse_compiler helpers for the default and explicit --cc command.

Testing before merging (2) (runs on the systems it can change; it doesn't hold the recommendation)

  • L2: The shared SDL initialization path still needs a Linux game run. When: Linux uses this path for microphone capture, playback and window initialization, including its bundled SDL2; the supplied run exercises Windows SDL3 only. Do: Run the named-microphone test on Linux through the reference-count wrap, checking that the meter and game audio continue; include the bundled SDL2 path.
  • L3: The requested Windows gameplay check remains outstanding. When: The reported Windows run exercises the menu meter at the title screen; it does not exercise the game’s microphone input while playing the ocarina. Do: Play with a named microphone and use it for the ocarina as described in Still to test, checking that input remains usable and no crash occurs.

@fix can do L1.

Checks: Still running: 10 checks.

More: does it help, other systems, switches, what was read

Does it help: Yes for the reproduced Windows case: main crashed about 70 seconds after microphone testing began following 240 menu opens; this head ran for 602 seconds without a crash and still showed input. The game-free test also reportedly fails on main and passes here.

Other systems: The same initialization function serves SDL audio, controllers and the Linux window. SDL2 and Linux playback share the changed path; the supplied game run covers Windows SDL3, not Linux or SDL2. The lock serializes first starts, and there are no SDL subsystem shutdown calls in the tree.

Switches: None added, changed or removed.

Reviewed: 476f38a513 against 3a0f7d8f7f: Read AGENTS.md, CONTRIBUTING.md, the pull request template, standards, both commits, the diff, both changed tests, and the changed initialization and related audio code. Skimmed the rest of host/hos_sdl.c and its callers. docs/review-checklist.md and ../Tooling/AGENTS.md were absent. No generated files or translations changed.; nothing run (a code review).

Checked and fine:

  • The started mask is protected by the same lock as SDL initialization, and failed starts are retried.
  • The regression fixture checks repeated microphone listing with a live stream and would fail if the started mask were not updated.
  • Both commits record AI assistance; no game-derived files, generated outputs, API version changes or switch changes are in the diff.

Testing: No code or tests were run, as requested. CI is still running; the reported Windows game run and test results were reviewed as evidence.

Overlaps and merge order: The description identifies WIP #3116 as touching a different part of hos_sdl.c; this fix remains useful for its in-game fallback.


Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.

**Recommendation: Approve.** The Windows reproduction supports the fix: the base crashed after repeated microphone listings, while this head kept the meter running for 602 seconds. Linux audio and the requested Windows gameplay run remain untested. Nothing blocking is left: what remains is for the author before merging (below). Recommend approval; not approved on the forge. The change prevents repeated microphone enumeration from wrapping SDL’s subsystem reference count and destroying an active stream. It adds a lock and a game-free regression test; the added work is limited to subsystem initialization calls. **Should fix (1)**: not blocking, but worth doing before merging. - **L1** `tests/test_sdl_init_once.py:133`: The new test treats the compiler setting as a single executable and defaults to gcc when run directly, so it does not fully honor CC. (more on the line) **Do:** Use the repository’s compiler_command and parse_compiler helpers for the default and explicit --cc command. **Testing before merging (2)** (runs on the systems it can change; it doesn't hold the recommendation) - **L2**: The shared SDL initialization path still needs a Linux game run. *When:* Linux uses this path for microphone capture, playback and window initialization, including its bundled SDL2; the supplied run exercises Windows SDL3 only. **Do:** Run the named-microphone test on Linux through the reference-count wrap, checking that the meter and game audio continue; include the bundled SDL2 path. - **L3**: The requested Windows gameplay check remains outstanding. *When:* The reported Windows run exercises the menu meter at the title screen; it does not exercise the game’s microphone input while playing the ocarina. **Do:** Play with a named microphone and use it for the ocarina as described in Still to test, checking that input remains usable and no crash occurs. `@fix` can do L1. **Checks:** Still running: 10 checks. <details> <summary>More: does it help, other systems, switches, what was read</summary> **Does it help:** Yes for the reproduced Windows case: main crashed about 70 seconds after microphone testing began following 240 menu opens; this head ran for 602 seconds without a crash and still showed input. The game-free test also reportedly fails on main and passes here. **Other systems:** The same initialization function serves SDL audio, controllers and the Linux window. SDL2 and Linux playback share the changed path; the supplied game run covers Windows SDL3, not Linux or SDL2. The lock serializes first starts, and there are no SDL subsystem shutdown calls in the tree. **Switches:** None added, changed or removed. **Reviewed:** 476f38a5133e against 3a0f7d8f7f34: Read AGENTS.md, CONTRIBUTING.md, the pull request template, standards, both commits, the diff, both changed tests, and the changed initialization and related audio code. Skimmed the rest of host/hos_sdl.c and its callers. docs/review-checklist.md and ../Tooling/AGENTS.md were absent. No generated files or translations changed.; nothing run (a code review). **Checked and fine:** - The started mask is protected by the same lock as SDL initialization, and failed starts are retried. - The regression fixture checks repeated microphone listing with a live stream and would fail if the started mask were not updated. - Both commits record AI assistance; no game-derived files, generated outputs, API version changes or switch changes are in the diff. **Testing:** No code or tests were run, as requested. CI is still running; the reported Windows game run and test results were reviewed as evidence. **Overlaps and merge order:** The description identifies WIP #3116 as touching a different part of hos_sdl.c; this fix remains useful for its in-game fallback. </details> --- <sub>Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.</sub>
@ -0,0 +130,4 @@
with tempfile.TemporaryDirectory(prefix="sdl-init-once-") as folder:
work = Path(folder)
(work / "fixture.c").write_text(source, encoding="utf-8")
exe = work / ("fixture.exe" if os.name == "nt" else "fixture")
Member

L1 (should fix): The new test treats the compiler setting as a single executable and defaults to gcc when run directly, so it does not fully honor CC.

When: With CC set to a compiler command such as ccache gcc, run_all passes that entire string as --cc; subprocess then looks for an executable literally named ccache gcc and the check fails. A direct invocation also ignores CC.

Do: Use the repository’s compiler_command and parse_compiler helpers for the default and explicit --cc command.

**L1** (should fix): The new test treats the compiler setting as a single executable and defaults to gcc when run directly, so it does not fully honor CC. *When:* With CC set to a compiler command such as `ccache gcc`, run_all passes that entire string as --cc; subprocess then looks for an executable literally named `ccache gcc` and the check fails. A direct invocation also ignores CC. **Do:** Use the repository’s compiler_command and parse_compiler helpers for the default and explicit --cc command.
HumanBean deleted branch fix/mic-sdl-init-once 2026-12-05 17:17:45 +00:00
Some checks are pending
CI / Host C for Windows (llvm-mingw, compile only) (pull_request) Blocked by required conditions
CI / Renderer build check (Windows, compile --only renderer, without and with FSR 4) (pull_request) Blocked by required conditions
CI / Renderer build check (Linux, compile --only renderer, without and with FSR 4) (pull_request) Blocked by required conditions
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Blocked by required conditions
CI / Game-free checks (run_all.py, part 2/2) (pull_request) Blocked by required conditions
CI / What the change needs (pull_request) Blocked by required conditions
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Blocked by required conditions
CI / Third-party parts and guide screenshots (pull_request) Blocked by required conditions
CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request) Blocked by required conditions
CI / Website build and checks (pull_request) Blocked by required conditions
PR description / Title and description (pull_request_target) Successful in 6s
Some workflows are waiting to be reviewed.
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
3 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
MagicBeanDev/Longshot!3228
No description provided.