silent_audio: NaN volumes refused, master volume under the lock, Reset revokes objects (RT-SILENT-AUDIO-VOLUME-AND-SPATIAL) #2521
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2521"
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 ubiquitarianism/leonida. Originally posted by Tyrannys on 2026-11-28T00:25:35Z.
Package RT-SILENT-AUDIO-VOLUME-AND-SPATIAL: item 4 of @kevincommits' finding on #1608 (https://github.com/ProjectLeonida/mandy/issues/1608#issuecomment-7226429207). Thank you for the find. Claim: https://github.com/ProjectLeonida/mandy/issues/1608#issuecomment-7230866389.
What changes (
runtime/shims/silent_audio.cpp)SimpleVolume::SetMasterVolume,StreamVolume::SetChannelVolumeandStreamVolume::SetAllVolumestestedlevel < 0.0f || level > 1.0f. That is false for NaN, so NaN was stored. One helper now checkslevel >= 0.0f && level <= 1.0f, asSpatialObject::SetVolumealready does.ISimpleAudioVolumeread and wroteclient_->master_andmute_with no lock. They are now private, behind accessors that takelock_, like the channel volumes.SpatialStream::Resetrevokes active objects. Microsoft's reference forISpatialAudioObjectRenderStreamBase::Resetsays resetting "causes all active ISpatialAudioObject instances to be revoked". Now each live object becomes inactive and its type can be activated again. Ends that a pass had queued are released. The stream keeps a list of its live objects (not owned). An object leaves the list first thing in its destructor, so a Reset that holds the lock still sees the whole object.Not changed:
ActivateSpatialAudioObjectduring an update pass. The finding suggests returningSPTLAUDCLNT_E_OUT_OF_ORDERthere. Microsoft's reference for that method lists no such return code. Activating objects inside a Begin/End pass is the documented pattern for dynamic objects, andsilent_audio_testitself activates its static objects that way. So this PR leaves it as it is.Tests (
silent_audio_test)SetMasterVolume(NaN),SetChannelVolume(7, NaN)andSetAllVolumeswith one NaN level are each refused, and the stored volumes stay as they were.StopandReset, a front-left object that was active reportsIsActive == FALSE.GetBufferon it givesSPTLAUDCLNT_E_RESOURCES_INVALIDATED. Front left can be activated again; on main that givesSPTLAUDCLNT_E_OBJECT_ALREADY_ACTIVE.On main, 6 of the new checks fail. With the fix, all 135 checks pass (3 runs).
The lock change has no test of its own: a data race on a float does not show up in a test. It now follows the same pattern as the channel volumes.
Profile M: RTX 4070 SUPER, Windows 11, Ryzen 7 9800X3D, MSVC RelWithDebInfo. CPU only. The full suite was not run because a boot was running.
git diff --checkandscripts/check_no_game_data.pyare clean. Open PRs #2133, #2134 and #2387 change other functions in this file. No game files used.AI-assisted (Claude Code).
🤖 Generated with Claude Code
Imported from ubiquitarianism/leonida. Originally posted by timbot103 on 2026-11-28T01:33:53Z.
Reviewed at head
53ea681a0on Windows 11 (MSVC 202219.44).Verification
silent_audio_test,com_shim_test, andgta6rt.silent_audio_test(5 consecutive runs): 135/135 checks passed on all 5 runs.com_shim_test(5 consecutive runs): 42/42 checks passed on all 5 runs.Findings (Request changes)
active_types_andobjects_races withReset()(silent_audio.cpp:775-782,817-831,894-897):ActivateSpatialAudioObject()setsactive_types_ |= t, releaseslock_, allocatesSpatialObject, then re-acquireslock_toobjects_.push_back(o). IfReset()runs in the gap, it clearsactive_types_ = 0without seeingoinobjects_;ois then pushed still active, and a secondActivateSpatialAudioObject(t)succeeds — leaving two live active spatial objects for the same static channel.~SpatialObject()has the inverse split:stream_->forget(this)andif (take_type()) stream_->release_type(type_)takelock_separately. IfReset()runs between them and a replacement object oftype_is activated, the dying object'stake_type()still returnstrueand clears the replacement'sactive_types_bit.objects_membership andactive_types_under a single lock acquisition in both activation and destruction closes both windows.objects_.push_back(o)leaks the object and lets an exception escape a COMHRESULTmethod (silent_audio.cpp:821-833):If
objects_.push_back(o)throwsstd::bad_alloc,o(and itsstream_->AddRef()andactive_types_reservation) is leaked and a C++ exception crosses the COM ABI boundary. Reserving/inserting under atry { ... } catch (const std::bad_alloc&)before committingactive_types_ |= t(or rolling back and returningE_OUTOFMEMORY) handles both issues together cleanly.The NaN volume rejection and locked master volume/mute access (
silent_audio.cpp:419-435,620-626) look solid.AI-assisted review + local MSVC verification.
Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-28T07:36:23Z.
#2521 | head
53ea681a07(merged cleanly with main09c1539483) |ctest --test-dir runtime/build -C RelWithDebInfo -R "^silent_audio$" --output-on-failure| red on main:silent_audio_testfails (135 check(s), 6 failure(s):SetMasterVolume/SetChannelVolume/SetAllVolumesacceptedNaNvia< 0.0f || > 1.0f, andSpatialStream::Reset()left activeSpatialObjects active) | green on PR+main:1/1CTest passes (silent_audio135/135checks in0.78s),check_no_game_data.py0violations. Source audit note: independently confirmed the two open review items insilent_audio.cpp(ActivateSpatialAudioObject/~SpatialObjectsplit lock windows betweenactive_types_andobjects_vs concurrentReset(), and unguardedobjects_.push_back(o)inside a COMHRESULTmethod) | Windows 11, RTX 3090 (610.88), Vulkan SDK 1.4.363.1 | AI-assisted: yesImported from ubiquitarianism/leonida. Originally posted by timbot103 on 2026-11-28T14:36:26Z.
Review: COMMENTED
Request changes after a static code audit against
53ea681a0+ec740bcc3. The range checks reject NaN, and the master volume and mute accessors consistently take the client lock.runtime/shims/silent_audio.cpp:821,:830and:895— Reset can run between type reservation and registration, or between unregistering and freeing a type. Either window can allow two active objects for one static type. Update the registry and reservation in one critical section on activation and final release.runtime/shims/silent_audio.cpp:830— A failed registry insertion throws out of the COM method and leaks the object, its stream reference and the type reservation. Use fixed slots or roll back and returnE_OUTOFMEMORY.runtime/shims/silent_audio.cpp:844and:907— An in-flightSetEndOfStreamcan enqueue a revoked object after Reset drains the queue, keeping the object and stream alive if no later call drains it. Recheck activity under the stream lock before enqueueing.runtime/shims/silent_audio.cpp:719— A validSetVolumecall still succeeds on an object revoked by Reset. ReturnSPTLAUDCLNT_E_RESOURCES_INVALIDATEDfor that object.The tests cover NaN refusal and sequential revocation. Cover the Reset races and allocation failure with deterministic tests, and make the existing reactivation check require a successful Begin.
AI-assisted.
Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-28T20:10:32Z.
Review: COMMENTED
Reviewed and locally tested
53ea681a0(runtime/shims/silent_audio.cpp,runtime/test/silent_audio_test.cpp).Local verification:
silent_audio_test(MSVC Release / Ninja) and ranctest -R ^silent_audio$: 1/1 passed.python -I scripts/check_no_game_data.py: passed.Holding off on approval because code inspection confirms the concurrency/lifecycle issues in
runtime/shims/silent_audio.cppraised earlier:ActivateAudioObjectreservesactive_types_under the lock, releases it to allocatenew SpatialObject, and re-acquires the lock forobjects_.push_back(o). A concurrentReset()in that window clearsactive_types_while leavingoactive, allowing duplicate static-type activation; alsoobjects_.push_back(o)can throwstd::bad_allocout of a COM method without rolling backoorrelease_type(t).SpatialObject::~SpatialObjectcallsforget(this)andrelease_type(type_)under two separate lock acquisitions instead of atomically under one lock.SetVolumeon an object invalidated byReset()still succeeds instead of returningSPTLAUDCLNT_E_RESOURCES_INVALIDATED.AI-assisted (Antigravity, Gemini).
Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-28T22:03:54Z.
Verified by OreoFR
c1ecf04ed+ PR head53ea681a0; green run in a merge package of 11 PRs, no new ctest failure vs mainctest -R "^silent_audio$"AI-assisted (Claude Code, Claude Opus 5.5).
Imported from ubiquitarianism/leonida. Originally posted by TheGeogeo on 2026-11-28T23:23:43Z.
Tested
53ea681a0merged (no commit) withmainaa918e5d9. GPUs tested: NVIDIA GeForce RTX 3080, driver 621.40, Windows 11 10.0.26300; MSVC 19.52 (Visual Studio 18), RelWithDebInfo, Ninja.silent_audiopasses.runtime/shims/silent_audio.cppback tomain, 6 of its 135 checks fail:SetMasterVolume(NaN) is refused and the volume staysSetChannelVolume(NaN) is refused and the volume staysSetAllVolumes with a NaN level is refused and changes nothingReset revokes the objects that were activea revoked object gets no bufferafter Reset, a type that was active can be activated againNo blocker from my side. AI-assisted (Claude Code).
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T23:25:41Z.
Merged after TheGeogeo's red/green check (check: green with this PR, red with
main's code, no regression over the relinked tests) and a re-check here: no conflict withmain670f1689c, same head as checked,no-game-datagreen, and the only ctest failures in the Windows/macOS CI jobs are tests this diff does not touch (known onmainor Vulkan: vk_xdxr_postbuild_readback vk_bindless_dimensions d3d12_compile_pool xbox_present ). The Python jobs fail onmaintoo.AI-assisted (Claude Code, Claude Opus 5.5), merged for MoonEyes.