fix(ngs2): accept empty waveform blocks and matrix levels on a voice without a format #5660

Merged
milescoviello merged 2 commits from upstream-pr/5660 into main 2026-10-15 12:54:20 +00:00
milescoviello commented 2026-10-14 05:02:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-14T05:02:03Z.


What

Steins;Gate Re:Boot (PPSA36591) ends when a button is pressed at its title screen:

[libc] unhandled exception 'St16invalid_argument' thrown from 0x78e31a46683e
terminate called after throwing an instance of 'std::invalid_argument'
  what():  AddWaveformBlocks: invalid argument

With temporary prints (not part of this PR), the title clears a sampler voice:

  • SCE_NGS2_SAMPLER_VOICE_PARAM_SETUP with an all-zero format. SetupSampler already accepts this and leaves the voice without a format (0 channels).
  • ADD_WAVEFORM_BLOCKS with num_blocks 0 and flags 0, with non-null blocks and data. AddWaveformBlocks refused it because the voice has no channels.
  • MATRIX_LEVELS for matrix 0 with num_levels 0. SetMatrixLevels refused it because there are no levels.

On a voice without a format, both are now accepted:

  • An add of no waveform blocks without APPEND applies RESET and the CONTINUE state, as it would on any voice, and adds nothing.
  • Matrix levels with no levels clear that matrix. An empty matrix is what a voice starts with and what ResetSetup leaves; Render.cpp treats it as no matrix.

KytyPS5's AddWaveformBlocks, which the libSceNgs2.native debt file already cites for the sampler, does the same for no blocks: its loop adds nothing, it takes CONTINUE for whether the voice accepts blocks, and it returns OK. It uses the channel count only to size each block.

Blocks with data, APPEND, and an empty matrix on a voice that has a format are still refused, so the existing check in Ngs2Render.cpp (zero levels on a set-up sampler voice) is unchanged. What the console returns for these calls is not measured; the libSceNgs2.native debt file records the assumption and the title.

ngs2_stream gains TestNoBlocksForClearedVoice: the title's sequence passes, and a block with data, APPEND, and an empty matrix with an out-of-range id are refused on that voice.

Tested

Ubuntu 24.04, GCC 13.3 (CI's compiler), Release with CI's configure flags, on main 75690a117:

  • With main's Voice.cpp and the new test, ngs2_stream fails with the title's message, AddWaveformBlocks: invalid argument. With the change it passes 5/5, and all 10 ngs2_* tests pass in 3 runs.
  • Steins;Gate Re:Boot (PPSA36591), relinked with --to-intel and run on Linux (RTX 4070 Ti), with scripted pad input from 8 s:
    • Without the change it stops about 20 s in with the lines above.
    • With only the AddWaveformBlocks part it stops about 20 s in with SetMatrixLevels: invalid argument.
    • With the change it runs the whole 160 s: it leaves the title screen and plays its opening narration at 59.94 fps (screenshots at 30 s intervals show successive lines of the narration).
  • @p3n1cillin reports a second title: Void Terrarium (PPSA03061) on Windows 11, MinGW GCC 15, Release, on main with #5153, #5425, #5140 and #5219. It stops 25 to 35 s in with AddWaveformBlocks: invalid argument on the same calls (a sampler voice with no format, ADD_WAVEFORM_BLOCKS with no blocks and flags 0). With the AddWaveformBlocks part of this change it keeps running for the whole 260 s run. That run did not reach the matrix-levels path.
  • @xXPBSXx checked Steins;Gate on Windows: Windows 10, MinGW-w64 GCC 15.2, Release. On main a077a88df it aborts with AddWaveformBlocks: invalid argument 3 s after the first Enter; with this head on main d92a8dad3, a 600 s run with 31 key presses reaches its limit with no exception, at about 59.9 FPS.
  • A MinGW-w64 GCC 13 -fsyntax-only compile of Voice.cpp has no errors.
  • tools/check_conventions.py --base upstream/main passes, and tools/pr_overlap.py --branch finds no overlap.

Not checked on a console. On Windows, only the Void Terrarium and Steins;Gate runs above.

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
  • Unblocks: none
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4853205821 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5660). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-14T05:02:03Z. --- ### What Steins;Gate Re:Boot (PPSA36591) ends when a button is pressed at its title screen: ``` [libc] unhandled exception 'St16invalid_argument' thrown from 0x78e31a46683e terminate called after throwing an instance of 'std::invalid_argument' what(): AddWaveformBlocks: invalid argument ``` With temporary prints (not part of this PR), the title clears a sampler voice: - `SCE_NGS2_SAMPLER_VOICE_PARAM_SETUP` with an all-zero format. `SetupSampler` already accepts this and leaves the voice without a format (0 channels). - `ADD_WAVEFORM_BLOCKS` with `num_blocks` 0 and flags 0, with non-null `blocks` and `data`. `AddWaveformBlocks` refused it because the voice has no channels. - `MATRIX_LEVELS` for matrix 0 with `num_levels` 0. `SetMatrixLevels` refused it because there are no levels. On a voice without a format, both are now accepted: - An add of no waveform blocks without `APPEND` applies `RESET` and the `CONTINUE` state, as it would on any voice, and adds nothing. - Matrix levels with no levels clear that matrix. An empty matrix is what a voice starts with and what `ResetSetup` leaves; `Render.cpp` treats it as no matrix. [KytyPS5's `AddWaveformBlocks`](https://github.com/KytyPS5/KytyPS5/blob/df5b9b92be7dfd463b47756b707d6d356a9f0550/src/libs/ngs2.cpp#L638-L690), which the libSceNgs2.native debt file already cites for the sampler, does the same for no blocks: its loop adds nothing, it takes `CONTINUE` for whether the voice accepts blocks, and it returns OK. It uses the channel count only to size each block. Blocks with data, `APPEND`, and an empty matrix on a voice that has a format are still refused, so the existing check in `Ngs2Render.cpp` (zero levels on a set-up sampler voice) is unchanged. What the console returns for these calls is not measured; the libSceNgs2.native debt file records the assumption and the title. `ngs2_stream` gains `TestNoBlocksForClearedVoice`: the title's sequence passes, and a block with data, `APPEND`, and an empty matrix with an out-of-range id are refused on that voice. ### Tested Ubuntu 24.04, GCC 13.3 (CI's compiler), Release with CI's configure flags, on `main` 75690a117: - With `main`'s `Voice.cpp` and the new test, `ngs2_stream` fails with the title's message, `AddWaveformBlocks: invalid argument`. With the change it passes 5/5, and all 10 `ngs2_*` tests pass in 3 runs. - Steins;Gate Re:Boot (PPSA36591), relinked with `--to-intel` and run on Linux (RTX 4070 Ti), with scripted pad input from 8 s: - Without the change it stops about 20 s in with the lines above. - With only the `AddWaveformBlocks` part it stops about 20 s in with `SetMatrixLevels: invalid argument`. - With the change it runs the whole 160 s: it leaves the title screen and plays its opening narration at 59.94 fps (screenshots at 30 s intervals show successive lines of the narration). - @p3n1cillin [reports a second title](https://github.com/boykopovar/AnyPS5/pull/5660#issuecomment-6166579106): Void Terrarium (PPSA03061) on Windows 11, MinGW GCC 15, Release, on `main` with #5153, #5425, #5140 and #5219. It stops 25 to 35 s in with `AddWaveformBlocks: invalid argument` on the same calls (a sampler voice with no format, `ADD_WAVEFORM_BLOCKS` with no blocks and flags 0). With the `AddWaveformBlocks` part of this change it keeps running for the whole 260 s run. That run did not reach the matrix-levels path. - @xXPBSXx [checked Steins;Gate on Windows](https://github.com/boykopovar/AnyPS5/pull/5660#issuecomment-6187446892): Windows 10, MinGW-w64 GCC 15.2, Release. On `main` a077a88df it aborts with `AddWaveformBlocks: invalid argument` 3 s after the first Enter; with this head on `main` d92a8dad3, a 600 s run with 31 key presses reaches its limit with no exception, at about 59.9 FPS. - A MinGW-w64 GCC 13 `-fsyntax-only` compile of `Voice.cpp` has no errors. - `tools/check_conventions.py --base upstream/main` passes, and `tools/pr_overlap.py --branch` finds no overlap. Not checked on a console. On Windows, only the Void Terrarium and Steins;Gate runs above. ### 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] Unblocks: none - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
p3n1cillin commented 2026-10-14 10:45:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by p3n1cillin on 2026-10-14T10:45:56Z.


A second title reaches this, plus a reference for the behaviour.

Void Terrarium (PPSA03061), Windows 11, MinGW GCC 15, Release. This is on main with #5153, #5425, #5140 and #5219, which it needs to get past its title screen. I drove it with Enter (Cross) through the title screen without a display. It stops 25–35 s in with AddWaveformBlocks: invalid argument. A local log of the call showed the same shape you describe: a sampler rack 0x1000 voice with channels=0 type=0x0, and ADD_WAVEFORM_BLOCKS with flags=0x0 num_blocks=0 and non-null blocks and data. With the same AddWaveformBlocks change, it keeps running for the whole 260 s run with key presses continuing; I didn't check by eye which screen it reaches. It didn't hit the matrix-levels path in that run.

Reference: KytyPS5's AddWaveformBlocks, which libSceNgs2.native's debt already cites for the sampler, does the same thing: with a count of 0 its loop adds nothing, it sets accepts_blocks from CONTINUE, and it returns OK. The channel count is used only to size each block. Its APPEND-style path without a decoder is not implemented there, which matches this PR still rejecting APPEND on a voice without a format.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6166579106 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5660#issuecomment-6166579106). Originally posted by [p3n1cillin](https://github.com/p3n1cillin) on 2026-10-14T10:45:56Z. --- A second title reaches this, plus a reference for the behaviour. **Void Terrarium (PPSA03061)**, Windows 11, MinGW GCC 15, Release. This is on `main` with #5153, #5425, #5140 and #5219, which it needs to get past its title screen. I drove it with Enter (Cross) through the title screen without a display. It stops 25–35 s in with `AddWaveformBlocks: invalid argument`. A local log of the call showed the same shape you describe: a sampler rack `0x1000` voice with `channels=0 type=0x0`, and `ADD_WAVEFORM_BLOCKS` with `flags=0x0 num_blocks=0` and non-null `blocks` and `data`. With the same `AddWaveformBlocks` change, it keeps running for the whole 260 s run with key presses continuing; I didn't check by eye which screen it reaches. It didn't hit the matrix-levels path in that run. **Reference:** [KytyPS5's `AddWaveformBlocks`](https://github.com/KytyPS5/KytyPS5/blob/df5b9b92be7dfd463b47756b707d6d356a9f0550/src/libs/ngs2.cpp#L638-L690), which libSceNgs2.native's debt already cites for the sampler, does the same thing: with a count of 0 its loop adds nothing, it sets `accepts_blocks` from `CONTINUE`, and it returns OK. The channel count is used only to size each block. Its `APPEND`-style path without a decoder is not implemented there, which matches this PR still rejecting `APPEND` on a voice without a format. AI-assisted: yes (Claude Code)
milescoviello commented 2026-10-14 10:46:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-14T10:46:46Z.


Thanks, that's very helpful. I added the Void Terrarium run and the KytyPS5 reference to the description.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6166596917 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5660#issuecomment-6166596917). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-14T10:46:46Z. --- Thanks, that's very helpful. I added the Void Terrarium run and the KytyPS5 reference to the description. AI-assisted: yes
xXPBSXx commented 2026-10-15 03:36:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-15T03:36:42Z.


Another title hits the same throw: Void Terrarium (PPSA03061), Windows 10, on main a077a88df5 (clean tree, no patches; fresh libs + relinker, title relinked with it). The title renders at about 60 FPS (window title FPS: 59.98). After an Enter key was posted to the game window (40 s into the run) it aborts: PPSA03061_rP/run_053148.err line 17 what(): AddWaveformBlocks: invalid argument, line 18 FATAL: abort() (SIGABRT); the throw is AddWaveformBlocks in core/libs/prx/libSceNgs2.native/src/Voice.cpp:208. A 120 s run of the same build without any key (run_050704.err, 15 lines) did not abort. I did not build #5660 on this title, so I cannot say whether it fixes this abort; I only confirm that the same message is reached by a second title. AI-assisted (Claude Code).

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6183820646 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5660#issuecomment-6183820646). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-15T03:36:42Z. --- Another title hits the same throw: Void Terrarium (PPSA03061), Windows 10, on `main` a077a88df5bc4ec26a3049aa721ac37ec8f02305 (clean tree, no patches; fresh `libs` + relinker, title relinked with it). The title renders at about 60 FPS (window title `FPS: 59.98`). After an Enter key was posted to the game window (40 s into the run) it aborts: `PPSA03061_rP/run_053148.err` line 17 `what(): AddWaveformBlocks: invalid argument`, line 18 `FATAL: abort() (SIGABRT)`; the throw is `AddWaveformBlocks` in `core/libs/prx/libSceNgs2.native/src/Voice.cpp:208`. A 120 s run of the same build without any key (`run_050704.err`, 15 lines) did not abort. I did not build #5660 on this title, so I cannot say whether it fixes this abort; I only confirm that the same message is reached by a second title. AI-assisted (Claude Code). AI-assisted (Claude Code).
milescoviello commented 2026-10-15 03:38:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-15T03:38:14Z.


Thanks for checking it on a clean main. That's the same stop p3n1cillin reported on Void Terrarium, where the AddWaveformBlocks part of this change kept the title running for the whole 260 s.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6183837427 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5660#issuecomment-6183837427). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-15T03:38:14Z. --- Thanks for checking it on a clean `main`. That's the same stop p3n1cillin reported on Void Terrarium, where the `AddWaveformBlocks` part of this change kept the title running for the whole 260 s. AI-assisted: yes
xXPBSXx commented 2026-10-15 08:03:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-15T08:03:47Z.


Windows check for STEINS;GATE RE:BOOT (PPSA36591): with this change the title no longer stops on AddWaveformBlocks: invalid argument.

  • Without it (main a077a88df): PPSA36591_rS2/run_054343.err line 17 what(): AddWaveformBlocks: invalid argument, line 18 FATAL: abort() (SIGABRT); the process died 3 s after the first Enter (sent 45 s after start).
  • With it (main d92a8dad390af1807cc91622b924252141816a5a + this head 5a921f0ef, clean merge, tree 58e18c8c8; libs rebuilt 09:51, relinker unchanged since 05:43): a 600 s run with 31 key presses (Enter, Down, Enter, Esc, Z, X, Space, every 17-19 s from +45 s, posted to the window) ran to the limit; run_095152.err has 24 lines (counted with Python), no exception and no FATAL; the window title shows about 59.9 FPS throughout. An earlier 240 s run with seven Enter presses on the same tree (run_063136.err) did not abort either.

Windows 10 (19045), MinGW-w64 GCC 15.2.0, Release. Limits: one title; I did not see the screen, so whether audio plays or the menu advances is not verified, only that the process no longer aborts; this pull request's own tests were not run; the "without" run is on a077a88df, I did not rerun d92a8dad3 without this change.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6187446892 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5660#issuecomment-6187446892). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-15T08:03:47Z. --- Windows check for STEINS;GATE RE:BOOT (PPSA36591): with this change the title no longer stops on `AddWaveformBlocks: invalid argument`. - Without it (`main` `a077a88df`): `PPSA36591_rS2/run_054343.err` line 17 `what(): AddWaveformBlocks: invalid argument`, line 18 `FATAL: abort() (SIGABRT)`; the process died 3 s after the first Enter (sent 45 s after start). - With it (`main` `d92a8dad390af1807cc91622b924252141816a5a` + this head `5a921f0ef`, clean merge, tree `58e18c8c8`; `libs` rebuilt 09:51, relinker unchanged since 05:43): a 600 s run with 31 key presses (Enter, Down, Enter, Esc, Z, X, Space, every 17-19 s from +45 s, posted to the window) ran to the limit; `run_095152.err` has 24 lines (counted with Python), no exception and no `FATAL`; the window title shows about 59.9 FPS throughout. An earlier 240 s run with seven Enter presses on the same tree (`run_063136.err`) did not abort either. Windows 10 (19045), MinGW-w64 GCC 15.2.0, Release. Limits: one title; I did not see the screen, so whether audio plays or the menu advances is not verified, only that the process no longer aborts; this pull request's own tests were not run; the "without" run is on `a077a88df`, I did not rerun `d92a8dad3` without this change. AI-assisted (Claude Code).
adriadam10 commented 2026-10-15 11:50:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-15T11:50:15Z.


Checked on the PR merged onto current main: ngs2_stream fails without the change and passes with it, all libSceNgs2.native tests and the scoped ctest are green, and the Steins;Gate / Void Terrarium runs from @p3n1cillin and @xXPBSXx on Windows cover the title behaviour.

Added one commit: the "NGS2 matrix levels" debt line still said a count of 0 always throws, so it now names the exception for a voice without a format. Merging once CI is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6191357614 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5660#issuecomment-6191357614). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-15T11:50:15Z. --- Checked on the PR merged onto current main: `ngs2_stream` fails without the change and passes with it, all libSceNgs2.native tests and the scoped ctest are green, and the Steins;Gate / Void Terrarium runs from @p3n1cillin and @xXPBSXx on Windows cover the title behaviour. Added one commit: the "NGS2 matrix levels" debt line still said a count of 0 always throws, so it now names the exception for a voice without a format. Merging once CI is green.
github-actions[bot] commented 2026-10-15 12:08:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T12:08:24Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#5548 docs/dev/debt/libSceNgs2.native.md L12-13

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
#1384 core/libs/prx/libSceNgs2.native/src/Voice.cpp
#5797 core/libs/prx/libSceNgs2.native/src/Voice.cpp
docs/dev/debt/libSceNgs2.native.md
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6191682364 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5660#issuecomment-6191682364). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-15T12:08:24Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #5548 | `docs/dev/debt/libSceNgs2.native.md` [L12-13](https://github.com/boykopovar/AnyPS5/blob/71bd2876e56a06e462e269b9d13616e07053ccad/docs/dev/debt/libSceNgs2.native.md#L12-L13) | | | Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap. | Pull request | Shared files not compared | |---|---| | #1384 | `core/libs/prx/libSceNgs2.native/src/Voice.cpp` | | #5797 | `core/libs/prx/libSceNgs2.native/src/Voice.cpp`<br>`docs/dev/debt/libSceNgs2.native.md` |
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!5660
No description provided.