silent_audio: NaN volumes refused, master volume under the lock, Reset revokes objects (RT-SILENT-AUDIO-VOLUME-AND-SPATIAL) #2521

Merged
Tyrannys merged 1 commit from upstream-pr/2521 into main 2026-11-28 23:25:38 +00:00
Tyrannys commented 2026-11-28 00:25:35 +00:00 (Migrated from github.com)

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)

  1. NaN volumes are refused. SimpleVolume::SetMasterVolume, StreamVolume::SetChannelVolume and StreamVolume::SetAllVolumes tested level < 0.0f || level > 1.0f. That is false for NaN, so NaN was stored. One helper now checks level >= 0.0f && level <= 1.0f, as SpatialObject::SetVolume already does.
  2. Master volume and mute under the lock. ISimpleAudioVolume read and wrote client_->master_ and mute_ with no lock. They are now private, behind accessors that take lock_, like the channel volumes.
  3. SpatialStream::Reset revokes active objects. Microsoft's reference for ISpatialAudioObjectRenderStreamBase::Reset says 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: ActivateSpatialAudioObject during an update pass. The finding suggests returning SPTLAUDCLNT_E_OUT_OF_ORDER there. 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, and silent_audio_test itself activates its static objects that way. So this PR leaves it as it is.

Tests (silent_audio_test)

  • SetMasterVolume(NaN), SetChannelVolume(7, NaN) and SetAllVolumes with one NaN level are each refused, and the stored volumes stay as they were.
  • After Stop and Reset, a front-left object that was active reports IsActive == FALSE. GetBuffer on it gives SPTLAUDCLNT_E_RESOURCES_INVALIDATED. Front left can be activated again; on main that gives SPTLAUDCLNT_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 --check and scripts/check_no_game_data.py are 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

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5534897293 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2521). Originally posted by [Tyrannys](https://github.com/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`) 1. **NaN volumes are refused.** `SimpleVolume::SetMasterVolume`, `StreamVolume::SetChannelVolume` and `StreamVolume::SetAllVolumes` tested `level < 0.0f || level > 1.0f`. That is false for NaN, so NaN was stored. One helper now checks `level >= 0.0f && level <= 1.0f`, as `SpatialObject::SetVolume` already does. 2. **Master volume and mute under the lock.** `ISimpleAudioVolume` read and wrote `client_->master_` and `mute_` with no lock. They are now private, behind accessors that take `lock_`, like the channel volumes. 3. **`SpatialStream::Reset` revokes active objects.** Microsoft's reference for `ISpatialAudioObjectRenderStreamBase::Reset` says 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: `ActivateSpatialAudioObject` during an update pass.** The finding suggests returning `SPTLAUDCLNT_E_OUT_OF_ORDER` there. 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, and `silent_audio_test` itself activates its static objects that way. So this PR leaves it as it is. ## Tests (`silent_audio_test`) - `SetMasterVolume(NaN)`, `SetChannelVolume(7, NaN)` and `SetAllVolumes` with one NaN level are each refused, and the stored volumes stay as they were. - After `Stop` and `Reset`, a front-left object that was active reports `IsActive == FALSE`. `GetBuffer` on it gives `SPTLAUDCLNT_E_RESOURCES_INVALIDATED`. Front left can be activated again; on main that gives `SPTLAUDCLNT_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 --check` and `scripts/check_no_game_data.py` are 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](https://claude.com/claude-code)
timbot103 commented 2026-11-28 01:33:53 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by timbot103 on 2026-11-28T01:33:53Z.


Reviewed at head 53ea681a0 on Windows 11 (MSVC 2022 19.44).

Verification

  • Built silent_audio_test, com_shim_test, and gta6rt.
  • 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)

  1. Lock split between active_types_ and objects_ races with Reset() (silent_audio.cpp:775-782, 817-831, 894-897):
    • ActivateSpatialAudioObject() sets active_types_ |= t, releases lock_, allocates SpatialObject, then re-acquires lock_ to objects_.push_back(o). If Reset() runs in the gap, it clears active_types_ = 0 without seeing o in objects_; o is then pushed still active, and a second ActivateSpatialAudioObject(t) succeeds — leaving two live active spatial objects for the same static channel.
    • ~SpatialObject() has the inverse split: stream_->forget(this) and if (take_type()) stream_->release_type(type_) take lock_ separately. If Reset() runs between them and a replacement object of type_ is activated, the dying object's take_type() still returns true and clears the replacement's active_types_ bit.
    • Updating objects_ membership and active_types_ under a single lock acquisition in both activation and destruction closes both windows.
  2. Failed objects_.push_back(o) leaks the object and lets an exception escape a COM HRESULT method (silent_audio.cpp:821-833):
    If objects_.push_back(o) throws std::bad_alloc, o (and its stream_->AddRef() and active_types_ reservation) is leaked and a C++ exception crosses the COM ABI boundary. Reserving/inserting under a try { ... } catch (const std::bad_alloc&) before committing active_types_ |= t (or rolling back and returning E_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.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7231756128 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2521#issuecomment-7231756128). Originally posted by [timbot103](https://github.com/timbot103) on 2026-11-28T01:33:53Z. --- Reviewed at head `53ea681a0` on Windows 11 (MSVC 2022 `19.44`). ### Verification - Built `silent_audio_test`, `com_shim_test`, and `gta6rt`. - `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) 1. **Lock split between `active_types_` and `objects_` races with `Reset()` (`silent_audio.cpp:775-782`, `817-831`, `894-897`):** - `ActivateSpatialAudioObject()` sets `active_types_ |= t`, releases `lock_`, allocates `SpatialObject`, then re-acquires `lock_` to `objects_.push_back(o)`. If `Reset()` runs in the gap, it clears `active_types_ = 0` without seeing `o` in `objects_`; `o` is then pushed still active, and a second `ActivateSpatialAudioObject(t)` succeeds — leaving two live active spatial objects for the same static channel. - `~SpatialObject()` has the inverse split: `stream_->forget(this)` and `if (take_type()) stream_->release_type(type_)` take `lock_` separately. If `Reset()` runs between them and a replacement object of `type_` is activated, the dying object's `take_type()` still returns `true` and clears the replacement's `active_types_` bit. - Updating `objects_` membership and `active_types_` under a single lock acquisition in both activation and destruction closes both windows. 2. **Failed `objects_.push_back(o)` leaks the object and lets an exception escape a COM `HRESULT` method (`silent_audio.cpp:821-833`):** If `objects_.push_back(o)` throws `std::bad_alloc`, `o` (and its `stream_->AddRef()` and `active_types_` reservation) is leaked and a C++ exception crosses the COM ABI boundary. Reserving/inserting under a `try { ... } catch (const std::bad_alloc&)` before committing `active_types_ |= t` (or rolling back and returning `E_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.
zmasi commented 2026-11-28 07:36:23 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-28T07:36:23Z.


#2521 | head 53ea681a07 (merged cleanly with main 09c1539483) | ctest --test-dir runtime/build -C RelWithDebInfo -R "^silent_audio$" --output-on-failure | red on main: silent_audio_test fails (135 check(s), 6 failure(s): SetMasterVolume/SetChannelVolume/SetAllVolumes accepted NaN via < 0.0f || > 1.0f, and SpatialStream::Reset() left active SpatialObjects active) | green on PR+main: 1/1 CTest passes (silent_audio 135/135 checks in 0.78s), check_no_game_data.py 0 violations. Source audit note: independently confirmed the two open review items in silent_audio.cpp (ActivateSpatialAudioObject / ~SpatialObject split lock windows between active_types_ and objects_ vs concurrent Reset(), and unguarded objects_.push_back(o) inside a COM HRESULT method) | Windows 11, RTX 3090 (610.88), Vulkan SDK 1.4.363.1 | AI-assisted: yes

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7236047644 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2521#issuecomment-7236047644). Originally posted by [zmasi](https://github.com/zmasi) on 2026-11-28T07:36:23Z. --- #2521 | head 53ea681a07fa9e3678b9d43e1fd3eb8dea0deece (merged cleanly with main 09c153948386fd658fe2f999f6176efbaa8c8345) | `ctest --test-dir runtime/build -C RelWithDebInfo -R "^silent_audio$" --output-on-failure` | red on main: `silent_audio_test` fails (`135 check(s), 6 failure(s)`: `SetMasterVolume`/`SetChannelVolume`/`SetAllVolumes` accepted `NaN` via `< 0.0f || > 1.0f`, and `SpatialStream::Reset()` left active `SpatialObject`s active) | green on PR+main: `1/1` CTest passes (`silent_audio` `135/135` checks in `0.78s`), `check_no_game_data.py` `0` violations. Source audit note: independently confirmed the two open review items in `silent_audio.cpp` (`ActivateSpatialAudioObject` / `~SpatialObject` split lock windows between `active_types_` and `objects_` vs concurrent `Reset()`, and unguarded `objects_.push_back(o)` inside a COM `HRESULT` method) | Windows 11, RTX 3090 (610.88), Vulkan SDK 1.4.363.1 | AI-assisted: yes
timbot103 commented 2026-11-28 14:36:26 +00:00 (Migrated from github.com)

Imported 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, :830 and :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 return E_OUTOFMEMORY.
  • runtime/shims/silent_audio.cpp:844 and :907 — An in-flight SetEndOfStream can 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 valid SetVolume call still succeeds on an object revoked by Reset. Return SPTLAUDCLNT_E_RESOURCES_INVALIDATED for 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.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6098418216 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2521#pullrequestreview-6098418216). Originally posted by [timbot103](https://github.com/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`, `:830` and `: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 return `E_OUTOFMEMORY`. - `runtime/shims/silent_audio.cpp:844` and `:907` — An in-flight `SetEndOfStream` can 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 valid `SetVolume` call still succeeds on an object revoked by Reset. Return `SPTLAUDCLNT_E_RESOURCES_INVALIDATED` for 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.
lixonik commented 2026-11-28 20:10:32 +00:00 (Migrated from github.com)

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:

  • Built silent_audio_test (MSVC Release / Ninja) and ran ctest -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.cpp raised earlier:

  1. ActivateAudioObject reserves active_types_ under the lock, releases it to allocate new SpatialObject, and re-acquires the lock for objects_.push_back(o). A concurrent Reset() in that window clears active_types_ while leaving o active, allowing duplicate static-type activation; also objects_.push_back(o) can throw std::bad_alloc out of a COM method without rolling back o or release_type(t).
  2. SpatialObject::~SpatialObject calls forget(this) and release_type(type_) under two separate lock acquisitions instead of atomically under one lock.
  3. SetVolume on an object invalidated by Reset() still succeeds instead of returning SPTLAUDCLNT_E_RESOURCES_INVALIDATED.

AI-assisted (Antigravity, Gemini).

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6099901150 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2521#pullrequestreview-6099901150). Originally posted by [lixonik](https://github.com/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: - Built `silent_audio_test` (MSVC Release / Ninja) and ran `ctest -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.cpp` raised earlier: 1. `ActivateAudioObject` reserves `active_types_` under the lock, releases it to allocate `new SpatialObject`, and re-acquires the lock for `objects_.push_back(o)`. A concurrent `Reset()` in that window clears `active_types_` while leaving `o` active, allowing duplicate static-type activation; also `objects_.push_back(o)` can throw `std::bad_alloc` out of a COM method without rolling back `o` or `release_type(t)`. 2. `SpatialObject::~SpatialObject` calls `forget(this)` and `release_type(type_)` under two separate lock acquisitions instead of atomically under one lock. 3. `SetVolume` on an object invalidated by `Reset()` still succeeds instead of returning `SPTLAUDCLNT_E_RESOURCES_INVALIDATED`. AI-assisted (Antigravity, Gemini).
OreoFR commented 2026-11-28 22:03:54 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-28T22:03:54Z.


Verified by OreoFR

  • Base: main c1ecf04ed + PR head 53ea681a0; green run in a merge package of 11 PRs, no new ctest failure vs main
  • Test: ctest -R "^silent_audio$"
  • Red on main: 6 failures of 135 (NaN volumes accepted, Reset does not revoke)
  • Green with the PR: OK
  • Verdict: READY
  • Machine: RTX 4070 Laptop 8 GB, NVIDIA 621.40, Intel Core Ultra 7 155H, Windows 11

AI-assisted (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7246470686 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2521#issuecomment-7246470686). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-28T22:03:54Z. --- **Verified by OreoFR** - Base: main `c1ecf04ed` + PR head `53ea681a0`; green run in a merge package of 11 PRs, no new ctest failure vs main - Test: `ctest -R "^silent_audio$"` - Red on main: 6 failures of 135 (NaN volumes accepted, Reset does not revoke) - Green with the PR: OK - Verdict: READY - Machine: RTX 4070 Laptop 8 GB, NVIDIA 621.40, Intel Core Ultra 7 155H, Windows 11 AI-assisted (Claude Code, Claude Opus 5.5).
TheGeogeo commented 2026-11-28 23:23:43 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by TheGeogeo on 2026-11-28T23:23:43Z.


Tested 53ea681a0 merged (no commit) with main aa918e5d9. GPUs tested: NVIDIA GeForce RTX 3080, driver 621.40, Windows 11 10.0.26300; MSVC 19.52 (Visual Studio 18), RelWithDebInfo, Ninja.

  • Green: silent_audio passes.
  • Red: with runtime/shims/silent_audio.cpp back to main, 6 of its 135 checks fail:
    • SetMasterVolume(NaN) is refused and the volume stays
    • SetChannelVolume(NaN) is refused and the volume stays
    • SetAllVolumes with a NaN level is refused and changes nothing
    • Reset revokes the objects that were active
    • a revoked object gets no buffer
    • after Reset, a type that was active can be activated again
  • No regression: the merge relinks 10 executables, and their 21 other tests pass.

No blocker from my side. AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7247401638 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2521#issuecomment-7247401638). Originally posted by [TheGeogeo](https://github.com/TheGeogeo) on 2026-11-28T23:23:43Z. --- Tested `53ea681a0` merged (no commit) with `main` `aa918e5d9`. GPUs tested: NVIDIA GeForce RTX 3080, driver 621.40, Windows 11 10.0.26300; MSVC 19.52 (Visual Studio 18), RelWithDebInfo, Ninja. - Green: `silent_audio` passes. - Red: with `runtime/shims/silent_audio.cpp` back to `main`, 6 of its 135 checks fail: - `SetMasterVolume(NaN) is refused and the volume stays` - `SetChannelVolume(NaN) is refused and the volume stays` - `SetAllVolumes with a NaN level is refused and changes nothing` - `Reset revokes the objects that were active` - `a revoked object gets no buffer` - `after Reset, a type that was active can be activated again` - No regression: the merge relinks 10 executables, and their 21 other tests pass. No blocker from my side. AI-assisted (Claude Code).
MoonEyes commented 2026-11-28 23:25:41 +00:00 (Migrated from github.com)

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 with main 670f1689c, same head as checked, no-game-data green, and the only ctest failures in the Windows/macOS CI jobs are tests this diff does not touch (known on main or Vulkan: vk_xdxr_postbuild_readback vk_bindless_dimensions d3d12_compile_pool xbox_present ). The Python jobs fail on main too.

AI-assisted (Claude Code, Claude Opus 5.5), merged for MoonEyes.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7247423472 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2521#issuecomment-7247423472). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-28T23:25:41Z. --- Merged after **TheGeogeo**'s red/green check ([check](https://github.com/ProjectLeonida/mandy/pull/2521#issuecomment-7247401638): green with this PR, red with `main`'s code, no regression over the relinked tests) and a re-check here: no conflict with `main` 670f1689c, same head as checked, `no-game-data` green, and the only ctest failures in the Windows/macOS CI jobs are tests this diff does not touch (known on `main` or Vulkan: vk_xdxr_postbuild_readback vk_bindless_dimensions d3d12_compile_pool xbox_present ). The Python jobs fail on `main` too. _AI-assisted (Claude Code, Claude Opus 5.5), merged for MoonEyes._
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
ProjectLeonida/mandy!2521
No description provided.