Skip to content

totk: grow Opus decoder registry and protect decoder lifetimes - #40

Merged
ly05010419 merged 1 commit into
ly05010419:mainfrom
hybtc8888:fix/totk-opus-decoder-lifetimes
Oct 19, 2026
Merged

ly05010419 merged 1 commit into
ly05010419:mainfrom
hybtc8888:fix/totk-opus-decoder-lifetimes

Conversation

@hybtc8888

Copy link
Copy Markdown
Contributor

Follow-up to #18: preserve reinitialization of the same guest decoder, remove the remaining fixed-capacity abort, and protect decoder state during use.

The current 256-entry table still exits with hardware Opus decoder table full when 257 distinct decoder objects are live. The same reproducer succeeds with this change. Each live decoder now owns a stable allocated node, which is removed and freed at Finalize. Reinitialization replaces the existing node's libopus state, preserving the behavior and one-time diagnostic added upstream. Per-decoder locking makes reinitialization and Finalize wait for an in-flight decode/reset/getter, while independent streams can decode in parallel.

Added make test-opus-codec, which uses real Opus packets without game data or an audio device. On Apple Silicon / macOS 27, both commands passed:

cd games/totk
make test-opus-codec OPUS_TEST_WORK=/tmp/totk-opus-asan
make test-opus-codec OPUS_TEST_WORK=/tmp/totk-opus-tsan OPUS_SANITIZERS=thread

Each run covers 512 simultaneously live decoders, 3,517 balanced node creations/finalizations, 8,691 same-object reinitializations, 8 worker threads, and reinitialize/Finalize waiting for a paused in-flight decode. PCM matches an independent libopus decoder across all five supported sample rates and mono/stereo. Invalid-input handling and final-range corruption rejection are also checked. ASan/UBSan and TSan report no errors (55,667 checks per run).

The 1.4.3 native runtime also rebuilt and passed its module-loader probe. The original in-game exit was observed on an older 64-slot build; the 257-object failure above is a synthetic test of current main. Long-session gameplay after this change remains unverified.

@ly05010419
ly05010419 merged commit 8c4d0f4 into ly05010419:main Oct 19, 2026
1 check passed
ly05010419 added a commit that referenced this pull request Oct 20, 2026
…ultrawide HUD, 1.4.3 survey, mods, controls.txt) into the Breath of the Wild branch

Resolved by hand: nvn_mtl.m (PR #34's paged-bitmap serial sets keep the serial forgetting of 635fb31: totk_serial_del
clears a bit; the memory line shows both; the BotW frame reset stays in mtl_present), build_app.py (make -j and the
per-game launcher defines), the Makefile (the BotW targets and the Opus test), loader.c (the #57 stale-reference handler
and 1.4.3's survey return address are TOTK-only: Breath of the Wild has no GAME_ADDR for them), world_survey.c (BotW
keeps its stub, with runtime_survey_sync), README (both update-history rows).

Found by the merged build: Breath of the Wild lacked runtime_output_size_current (frontend.m's shortcut text) and
runtime_survey_sync (hle_nvn.c); and the add-on content file handles shared fs_host.c's 0x200000000 range, so closing a
host file at the title ended the game ("close invalid add-on content handle"): they now start at 0x400000000.

Tested on the merged binaries: TOTK 1.2.1 jump session (anomalies 0, occlusion normal, serial set 48,606 / 13 pages),
Breath of the Wild DLC + key 3 (k3a6) and key 2 (k2c, 11 of 12 pairs within 5 px).

Co-Authored-By: Claude Fable 5.1 <[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