fix(coreaudio): share one AudioQueue per format and recreate failed start handles #338
No reviewers
Labels
No labels
accessibility
bug
claimed
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
tester report
urgent
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/LakshanSivakumar--Native-Victory-macOS!338
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-337"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@Sheffy007 on GitHub · 2026-11-27 12:47 UTC · original
Sheffy007:fix/coreaudio-shared-output-queue→main· +652 −95 · 2 files · 1 commits · merged 2026-11-27 16:14 UTCCloses #337
Refs #8
Refs #258
Problem
In world runs on current
main(with #288 merged), sound still cuts out when the title repeatedly re-activates its spatial audio stream during heavy world-load pressure:#issuecomment-7217386312):AudioQueueStart failed with OSStatus 2003329396('what') on 4 of 14 stream activations in the default run and 6 of 32 in the heap run (0%free memory), falling back to silence.Every
XAudio2engine, WASAPIIAudioClient::Initialize, andISpatialAudioClient::ActivateSpatialAudioStreamcallscoreaudio::open_default(48_000, 2, render), which previously opened and started a separate AudioToolboxAudioQueue(AudioQueueNewOutput+AudioQueueStart) each time. When a mid-run spatial stream re-activation hit'what'fromcoreaudiodunder load, #288 retriedAudioQueueStarton the same failed handle (stalling500 ms) and then permanently bound the newly activated stream toSilent("no audio device: sound is mixed and dropped") even while the process's initial 48 kHz stereoAudioQueuekept running.Fix
AudioQueueper(rate, channels)(Hub/MixerQueue): ActiveCoreAudiohandles attach aSlotto the running(48_000, 2)queue and mix in userspace (f32sum into pre-allocated scratch buffers inrefillwith zero heap allocations on the callback thread; silence when zero streams are attached). Mid-run spatial/WASAPI/XAudio2 stream activations attach in userspace without callingAudioQueueNewOutputorAudioQueueStartagain, and only reopen ifAudioQueueEnqueueBufferreports a runtime device error.AudioQueueStartretry: When opening a hardwareAudioQueuefor the first time (or after a runtime failure), each retry disposes the failedAudioQueueRefand allocates/primes a fresh queue handle instead of retryingAudioQueueStarton the broken handle.Dropwithout callback lock cycles:refillinvokes each slot'sRenderoutside the slot mutex (in_call: Option<ThreadId>+Condvar), waiting for any in-flight callback from other threads onDropwhile avoiding self-deadlock if a callback ever drops its ownOutputre-entrantly.Tests
host_posix::coreaudio::tests::the_device_opens_pulls_frames_and_closes&the_silent_output_keeps_timehost_posix::coreaudio::tests::streams_share_one_queue_mix_and_survive_repeated_reactivations(2 concurrent streams mix0.25 + 0.50 = 0.75, idle outputs0.0, and 32 stream tear-downs/re-activations make1AudioQueueNewOutputand1AudioQueueStartcall total)host_posix::coreaudio::tests::start_retry_disposes_failed_queue_and_recovers_after_runtime_error('what'on attempt 0 disposes0x1001and starts fresh0x1002; runtimeAudioQueueEnqueueBufferfailure notifies active streams and reopens0x1003)host_posix::coreaudio::tests::reentrant_drop_inside_render_callback_does_not_deadlock@Olima34 on GitHub · 2026-11-27 13:28 UTC · original
Check report:
45ed3281checked together with #338 and #341 merged onto main60baf130(M5 Pro 48 GB, arm64, with the converter):cargo test -p victory-hle -p victory -p victory-gpu -p xtask: all pass (victory-hle 144 passed, main 141 with the new tests of both PRs; victory-gpu 347 passed).cargo clippy --workspace --all-targets --target x86_64-pc-windows-gnullvm -- -D warnings: clean.cargo xtask policy: ok.Result: passes, and no review question is open. It can't be merged from my side (the branch rule requires an approving review), so it's ready for the maintainer. @Sheffy007, if you get a world run with it,
tools/macos/run-summary.shprints the audio section (spatial stream activations, whether the device kept playing); posting that before/after would show #337 is fixed in game.@LakshanSivakumar on GitHub · 2026-11-27 16:15 UTC · original
Merged in
4cf84c83. Before pushing I ran the tests (native arm64), Windows clippy, the policy check, a release build, and one headless game run of the exact tree (170 s, Series S): menus at 30 fps, the world entered at about 81 s and kept presenting to the end at about 1 frame a second, 0 GPU errors, no crash. Audio kept playing through the run. Thanks.