Skip to content

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

Merged
adriadam10 merged 2 commits into
boykopovar:mainfrom
milescoviello:fix/ngs2-empty-waveform-blocks
Oct 15, 2026
Merged

adriadam10 merged 2 commits into
boykopovar:mainfrom
milescoviello:fix/ngs2-empty-waveform-blocks

Conversation

@milescoviello

@milescoviello milescoviello commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

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 75690a1:

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

@p3n1cillin

Copy link
Copy Markdown
Contributor

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)

@milescoviello

Copy link
Copy Markdown
Contributor Author

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

AI-assisted: yes

@xXPBSXx

xXPBSXx commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

Another title hits the same throw: Void Terrarium (PPSA03061), Windows 10, on main a077a88 (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

Copy link
Copy Markdown
Contributor Author

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

xXPBSXx commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

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 adriadam10 self-assigned this Oct 15, 2026
@milescoviello
milescoviello force-pushed the fix/ngs2-empty-waveform-blocks branch from 5a921f0 to 91b319e Compare October 15, 2026 11:39
milescoviello and others added 2 commits October 15, 2026 13:48
…without a format

A sampler voice set up with an all-zero format has no channels. Adding no
waveform blocks to it, or setting a matrix with no levels, threw
std::invalid_argument, which ends the title.

Accept both on such a voice: the empty add only applies RESET and the
CONTINUE state, and the empty matrix clears that matrix, which rendering
already treats as unset. Blocks with data, APPEND, and an empty matrix on
a voice with a format are still refused.

Steins;Gate Re:Boot (PPSA36591) clears a voice this way when a button is
pressed at its title screen.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ception

Co-Authored-By: Claude <noreply@anthropic.com>
@adriadam10

Copy link
Copy Markdown
Collaborator

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

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants