fix(coreaudio): share one AudioQueue per format and recreate failed start handles #337
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/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?
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Sheffy007 on 2026-11-27T12:47:48Z.
Closes #336
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_deadlockImported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Olima34 on 2026-11-27T13:28:51Z.
Check report:
45ed3281checked together with #337 and #340 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 #336 is fixed in game.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T16:15:16Z.
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.