Skip to content

totk: fix hardware Opus decoder slot leak ("decoder table full" crash) - #18

Merged
ly05010419 merged 1 commit into
ly05010419:mainfrom
koshtaru:fix/totk-opus-decoder-slot-leak
Oct 19, 2026
Merged

ly05010419 merged 1 commit into
ly05010419:mainfrom
koshtaru:fix/totk-opus-decoder-slot-leak

Conversation

@koshtaru

Copy link
Copy Markdown
Contributor

Problem

On TotK 1.0.0 (clean XCI, M3 Pro, macOS 27), the app aborted twice during normal play, after about 30 and about 7 minutes. The last log line both times was:

[movie] 3000 frames, decode 2.88 ms per frame
[totk] FAIL: hardware Opus decoder table full

initialize() in games/totk/runtime/opus_codec.c always takes a free slot. If the game calls InitializeHardwareOpusDecoder again on a decoder object it never finalized, the old slot (and its libopus state) is never released. The 64-entry table then fills up and runtime_fail aborts the game.

Fix

  • In initialize(), if a live slot already belongs to the same guest decoder object, destroy its old libopus state and reuse that slot instead of taking a new one.
  • Raise MAX_DECODERS from 64 to 256 for headroom.

finalize(), find() and the decode and integrity checks are unchanged.

Testing

I rebuilt the app with build_app.py from a clean 1.0.0 XCI. Gameplay since the rebuild has had no crash so far, but long sessions are still being tested. I haven't confirmed with logging exactly which call path re-initializes without finalizing.

The game can call InitializeHardwareOpusDecoder again on a decoder object
without finalizing it first. Each call took a new slot, so after enough
cutscenes/streams the 64-entry table filled and the runtime aborted with
'hardware Opus decoder table full' (seen after ~7 and ~30 min of play on
1.0.0). Reuse the existing slot for the same guest object (destroying the
old libopus state) and raise the table to 256 as headroom.
@ly05010419
ly05010419 merged commit 31d5aa8 into ly05010419:main Oct 19, 2026
1 check passed
ly05010419 added a commit that referenced this pull request Oct 19, 2026
…without Finalize

PR #18 reuses the slot; the line tells which session hits that path (our host writes none of the SDK's
HardwareOpusDecoderType fields, which the game may test before it initializes).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
ly05010419 added a commit that referenced this pull request Oct 19, 2026
…der has a lock for its lifetime

Defensive: the game keeps far fewer than 256 decoders alive; issue #9's exit came from repeated
Initialize without Finalize, fixed by PR #18. Resolved with main: a header that records no final
range (a40bc87) is still decoded without the check, now with the decoder released. The peak line
is printed only past the old 64 (at 65 and every power of two) unless TOTK_CODEC_TRACE is set,
and the probe checks a zero range is accepted. make test-opus-codec passes with ASan+UBSan and
TSan (512 live decoders, 8 threads); 1.4.3 plays audio in the world.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01AZC16EYkS2AmLMgumTJaXJ
0x1233333 pushed a commit to 0x1233333/MacNativeGames that referenced this pull request Oct 20, 2026
…without Finalize

PR ly05010419#18 reuses the slot; the line tells which session hits that path (our host writes none of the SDK's
HardwareOpusDecoderType fields, which the game may test before it initializes).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants