fix(libSceNgs2): return INVALID_VOICE_ACCESS for PLAY on a voice that was never set up #9926

Merged
JAB-dev merged 7 commits from upstream-pr/9926 into main 2026-10-25 09:22:17 +00:00
JAB-dev commented 2026-10-22 22:00:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JAB-dev on 2026-10-22T22:00:47Z.


What

sceNgs2VoiceControl and sceNgs2VoiceRunCommands now fail a PLAY event on a voice that has no channels (never set up). They return 0x804A8351 (SCE_NGS2_ERROR_INVALID_VOICE_ACCESS), the voice stays idle with state flags 0, and the rest of a parameter list after the failing event is not applied. Before, the voice went to the playing state and never left it: with no channels the renderer never reaches the code that ends a voice with no data left, so its state flags stayed INUSE | PLAYING forever.

A title that frees its sound slots by polling sceNgs2VoiceGetStateFlags for 0 then leaks one slot per such sound. Void Terrarium (PPSA03061, US) does this: it sends a stop-immediately event, an add of no waveform blocks and a play event to a voice it never set up. With a fresh save its pool of 32 sound-effect slots fills after the first level, and the next sound dereferences a null effect:

FATAL: unhandled exception 0xc0000005
  rip 0x0000000140259537 app-plain.exe+0x259537
  read of 0x000000000000002c

The title does not crash on a console, which matches the library behaviour below.

Source

Measured by loading the decrypted PS5 firmware 3.20 and 4.03 libSceNgs2.native.sprx in a test harness and calling it directly (inputs and outputs only; nothing from the firmware is in the repository). The two firmware builds give identical results. The title's own calls only work with this module: it sends the PS5 event values (PLAY is 1), the 144-byte system option and the 0x108-byte delay parameter, and the plain libSceNgs2.sprx in the same firmware is the PS4 library (PS4 event values and option sizes). With a sampler voice patched to a mastering voice at 48000 Hz and grain 256:

Sent to a voice that was never set up Return code State flags after 6 renders
stop-immediately, add of no blocks, play play 0x804A8351, the others 0 0
play only 0x804A8351 0
add of no blocks only 0 0
the same plus a pitch parameter before the play pitch 0, play 0x804A8351 0
play through sceNgs2VoiceRunCommands 0x804A8351 0
all-zero setup, then play setup 0, play 0x804A8351 0
set up, then an all-zero setup, then play all 0 the voice keeps its earlier setup; a play after it succeeds with flags 1
play on a never-set-up submixer, reverb, mastering or custom submixer voice 0x804A8351 each 0
the first row, then setup, patch, a real block and play all 0 plays normally
list [volume, play, volume] play 0x804A8351; the first volume is applied, the second is not 0
list [play, setup] play 0x804A8351; the setup is not applied 0

SCE_NGS2_ERROR_INVALID_VOICE_ACCESS is 0x804A8351 in the PS5 SDK ngs2_errors.h. The PS4 11.00 library returns 0x804A0052 for the same sequence, so a PS4 value is not the PS5 one. The guard covers every rack, as the module does. An all-zero setup on a voice that already has a setup is ignored, as in the module, so the guard does not fail a play after it. Two behaviours of the module are not reproduced and are listed in the library's technical debt file: the flags of a set-up voice given no blocks, and an add of no blocks to a voice that already played and ended.

I found no open or merged PR that implements this guard. The open PRs that touch SetEvent or the NGS2 error constants do something else: a different reverb change and error codes for other calls.

Tested

Windows 11 x64, GCC 15.2 (WinLibs), Release, on main 8eb8e39207.

  • The new ngs2_voiceevents test sends the play through both entry points to a sampler voice with no setup and checks the return code, state flags 0 and silent output over three renders. It then checks that a play after setup succeeds with exactly INUSE, in a command, in one parameter list after the setup, and that the same list with the play first still fails and leaves the voice idle. Unset submixer, reverb and mastering voices fail the same way. On main it aborts at line 26 (NGS2 check failed at line 26).
  • Mutations, each caught by the test (the first three before the all-zero change, the last for it): removing the channels condition (line 106), changing the event the guard tests (line 26) returning success from the guard (line 26), and resetting a configured voice on an all-zero setup (line 120).
  • All 14 ngs2 tests pass (ctest -R ngs2). tools/check_conventions.py --base origin/main and git diff --check pass.
  • Void Terrarium, fresh save, replaying a recorded controller session up to the point where it crashed: before the change the pool is full at 134 s and the game crashes at 228 s. With the change the same replay ran 620 s without a crash and used at most 3 of the 32 slots.
  • Linux not tested.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: PPSA03061 (no bring-up discussion for the US copy yet; the EU copy's is Void Terrarium++)
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4974698070 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9926). Originally posted by [JAB-dev](https://github.com/JAB-dev) on 2026-10-22T22:00:47Z. --- ### What `sceNgs2VoiceControl` and `sceNgs2VoiceRunCommands` now fail a `PLAY` event on a voice that has no channels (never set up). They return `0x804A8351` (`SCE_NGS2_ERROR_INVALID_VOICE_ACCESS`), the voice stays idle with state flags 0, and the rest of a parameter list after the failing event is not applied. Before, the voice went to the playing state and never left it: with no channels the renderer never reaches the code that ends a voice with no data left, so its state flags stayed `INUSE | PLAYING` forever. A title that frees its sound slots by polling `sceNgs2VoiceGetStateFlags` for 0 then leaks one slot per such sound. Void Terrarium (PPSA03061, US) does this: it sends a stop-immediately event, an add of no waveform blocks and a play event to a voice it never set up. With a fresh save its pool of 32 sound-effect slots fills after the first level, and the next sound dereferences a null effect: ``` FATAL: unhandled exception 0xc0000005 rip 0x0000000140259537 app-plain.exe+0x259537 read of 0x000000000000002c ``` The title does not crash on a console, which matches the library behaviour below. ### Source Measured by loading the decrypted PS5 firmware 3.20 and 4.03 `libSceNgs2.native.sprx` in a test harness and calling it directly (inputs and outputs only; nothing from the firmware is in the repository). The two firmware builds give identical results. The title's own calls only work with this module: it sends the PS5 event values (PLAY is 1), the 144-byte system option and the 0x108-byte delay parameter, and the plain `libSceNgs2.sprx` in the same firmware is the PS4 library (PS4 event values and option sizes). With a sampler voice patched to a mastering voice at 48000 Hz and grain 256: | Sent to a voice that was never set up | Return code | State flags after 6 renders | |---|---|---| | stop-immediately, add of no blocks, play | play `0x804A8351`, the others 0 | 0 | | play only | `0x804A8351` | 0 | | add of no blocks only | 0 | 0 | | the same plus a pitch parameter before the play | pitch 0, play `0x804A8351` | 0 | | play through `sceNgs2VoiceRunCommands` | `0x804A8351` | 0 | | all-zero setup, then play | setup 0, play `0x804A8351` | 0 | | set up, then an all-zero setup, then play | all 0 | the voice keeps its earlier setup; a play after it succeeds with flags 1 | | play on a never-set-up submixer, reverb, mastering or custom submixer voice | `0x804A8351` each | 0 | | the first row, then setup, patch, a real block and play | all 0 | plays normally | | list [volume, play, volume] | play `0x804A8351`; the first volume is applied, the second is not | 0 | | list [play, setup] | play `0x804A8351`; the setup is not applied | 0 | `SCE_NGS2_ERROR_INVALID_VOICE_ACCESS` is `0x804A8351` in the PS5 SDK `ngs2_errors.h`. The PS4 11.00 library returns `0x804A0052` for the same sequence, so a PS4 value is not the PS5 one. The guard covers every rack, as the module does. An all-zero setup on a voice that already has a setup is ignored, as in the module, so the guard does not fail a play after it. Two behaviours of the module are not reproduced and are listed in the library's technical debt file: the flags of a set-up voice given no blocks, and an add of no blocks to a voice that already played and ended. I found no open or merged PR that implements this guard. The open PRs that touch `SetEvent` or the NGS2 error constants do something else: a different reverb change and error codes for other calls. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Windows 11 x64, GCC 15.2 (WinLibs), Release, on `main` 8eb8e39207. - The new `ngs2_voiceevents` test sends the play through both entry points to a sampler voice with no setup and checks the return code, state flags 0 and silent output over three renders. It then checks that a play after setup succeeds with exactly `INUSE`, in a command, in one parameter list after the setup, and that the same list with the play first still fails and leaves the voice idle. Unset submixer, reverb and mastering voices fail the same way. On `main` it aborts at line 26 (`NGS2 check failed at line 26`). - Mutations, each caught by the test (the first three before the all-zero change, the last for it): removing the channels condition (line 106), changing the event the guard tests (line 26) returning success from the guard (line 26), and resetting a configured voice on an all-zero setup (line 120). - All 14 `ngs2` tests pass (`ctest -R ngs2`). `tools/check_conventions.py --base origin/main` and `git diff --check` pass. - Void Terrarium, fresh save, replaying a recorded controller session up to the point where it crashed: before the change the pool is full at 134 s and the game crashes at 228 s. With the change the same replay ran 620 s without a crash and used at most 3 of the 32 slots. - Linux not tested. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: PPSA03061 (no bring-up discussion for the US copy yet; the EU copy's is [Void Terrarium++](https://github.com/boykopovar/AnyPS5/discussions/5665)) - [x] GPUs tested: n/a - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-10-23 05:46:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T05:46:52Z.

Review: COMMENTED


The guard and regression coverage match the firmware observations in the description: both entry points return SCE_NGS2_ERROR_INVALID_VOICE_ACCESS (0x804A8351) before setting PLAY, and the test covers state/output and setup recovery. The title currently says INVALID_NUM_CHANNELS, which does not match the implemented/tested error name; please correct it or explain the distinction.\n\nCurrent-main sync reports 304 commits behind with core/libs/prx/libSceNgs2.native/include/Ngs2Types.hpp and docs/dev/debt/libSceNgs2.native.md changed on both sides since merge base. Please refresh and preserve the intervening error/type and debt entries, then rerun the NGS2 suite. Current-main whitespace and conventions pass.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5624409569 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9926#pullrequestreview-5624409569). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-23T05:46:52Z. **Review:** COMMENTED --- The guard and regression coverage match the firmware observations in the description: both entry points return `SCE_NGS2_ERROR_INVALID_VOICE_ACCESS` (`0x804A8351`) before setting PLAY, and the test covers state/output and setup recovery. The title currently says `INVALID_NUM_CHANNELS`, which does not match the implemented/tested error name; please correct it or explain the distinction.\n\nCurrent-main sync reports 304 commits behind with `core/libs/prx/libSceNgs2.native/include/Ngs2Types.hpp` and `docs/dev/debt/libSceNgs2.native.md` changed on both sides since merge base. Please refresh and preserve the intervening error/type and debt entries, then rerun the NGS2 suite. Current-main whitespace and conventions pass.
MarcZX10 commented 2026-10-23 05:46:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T05:46:53Z.

Review: DISMISSED


Please correct the PR title: it says INVALID_NUM_CHANNELS, but the described firmware measurement, implementation, and tests all use SCE_NGS2_ERROR_INVALID_VOICE_ACCESS (0x804A8351). Also refresh onto current main and resolve/preserve changes in the shared Ngs2Types.hpp and libSceNgs2.native.md files; current sync is 304 commits behind. After refreshing, rerun the focused NGS2 tests. The exact-head code and reported Windows/title evidence otherwise look sound; current-main conventions and diff-check pass.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5624409709 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9926#pullrequestreview-5624409709). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-23T05:46:53Z. **Review:** DISMISSED --- Please correct the PR title: it says `INVALID_NUM_CHANNELS`, but the described firmware measurement, implementation, and tests all use `SCE_NGS2_ERROR_INVALID_VOICE_ACCESS` (`0x804A8351`). Also refresh onto current main and resolve/preserve changes in the shared `Ngs2Types.hpp` and `libSceNgs2.native.md` files; current sync is 304 commits behind. After refreshing, rerun the focused NGS2 tests. The exact-head code and reported Windows/title evidence otherwise look sound; current-main conventions and diff-check pass.
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
boykopovar/AnyPS5!9926
No description provided.