Repository navigation
Ocarina of Time: a full model heap no longer crashes the model rebuild (from HookLink) - #2497
oliverames wants to merge 1 commit into
Conversation
… rebuild: its CPU buffers and GPU memory are tried again in the heap's parents (DM_HEAP_RETRY, on by default) Symptom: Ocarina of Time crashed about 11 minutes in on an iPhone (HookLink's test build): "BufferInitialize: pool has no storage", then h_nvnMemoryPoolGetFlags on a null pool, backtrace main+0x436fb4. Cause: the game's OptimizeChangeBank thread rebuilds a model's material block (main+0x4366e0) with memory from small per-model heaps and checks none of its four allocations: two CPU buffers from the heap's tryAlloc (lr main+0x436910, +0x436da4) and two blocks of GPU memory from main+0x502050 (lr main+0x436f1c, +0x437098). When the heap is full the game goes on with a null block. Hookshot found the same on PCs (NotRexed/Hookshot issue 1697); its notes give these sites and the sead heap layout (+0x38 the parent). Fix: patches.py heap_retry, stubs after the game's call: a failure is tried again in the heap's parents (at most 16 for the CPU buffers), the GPU memory last in the game's default heap, then the game goes on where it would have. State page +0x170 / +0x174 count the blocks made elsewhere and the power line logs them when they change; DM_HEAP_RETRY=0 (+0x17c) leaves the game as shipped. v131072 only. Checked: patch_nso.py on this game's v131072 main patches all four sites (main.changed.tsv) after checking each one's original word; host build; iOS compile check 263 files, 0 failed; test_patches, test_env_switches, test_docs pass. Not run in the game here, and HookLink had not run it on a device when it shipped in 1.8.5. Ported from HookLink's commit cc6e6b4 (https://github.com/dsi-hub/nxnative/tree/hooklink, MIT); the stubs are theirs. Changes from it: the call sits after dynamic_resolution (main's frame_step has no wide view or half-rate hooks), and a game note. Co-authored-by: dsi-hub <260802842+dsi-hub@users.noreply.github.com>
2de109e to
581148a
Compare
|
Hi! This branch is based on a To pick up the fix, merge the current git fetch origin
git merge origin/main
git pushIf the merge has conflicts, ask here if you want help with them. |
|
Thanks @oliverames for porting this over (and thanks to @dsi-hub for the original work). I'm closing this without merging for now:
What was checked: Reviewed the PR diff against Ocarina of Time v131072 Still open: The crash remains tracked in #1445. The next step is reproducing it on plain current |
What and why
HookLink's iPhone build of Ocarina of Time crashed about 11 minutes in:
BufferInitialize: pool has no storage, thenh_nvnMemoryPoolGetFlagson a null pool, with the backtrace at main+0x436fb4.The game's OptimizeChangeBank thread rebuilds a model's material block (main+0x4366e0) with memory from small per-model heaps, and it checks none of its four allocations: two CPU buffers from the heap's
tryAlloc(returning to main+0x436910 and +0x436da4) and two blocks of GPU memory from main+0x502050 (returning to +0x436f1c and +0x437098). When the heap is full, the game goes on with a null block. Hookshot found the same crash on PCs (NotRexed/Hookshot issue 1697), and its notes give these sites and the sead heap layout (the parent at +0x38).patches.pyheap_retryadds stubs after each of the four calls. A failed allocation is tried again in the heap's parents (at most 16 for the CPU buffers), and the GPU memory last in the game's default heap; then the game goes on where it would have. State page +0x170 and +0x174 count the blocks made elsewhere, and the power line logsfull model heapwhen they change.DM_HEAP_RETRY=0(+0x17c) leaves the game as shipped. It applies to v131072 only.Ported from HookLink's commit cc6e6b47 on the
hooklinkbranch of dsi-hub/nxnative (MIT), with dsi-hub as co-author; the stubs are theirs. On main the call sits afterdynamic_resolution, since main'sframe_stephas none of HookLink's wide-view or half-rate hooks. The game note gains a line under Memory. Offsets 0x170 to 0x17c on the state page are unused on main (the dynamic-resolution stub uses +0x40 and +0x200 onward;loader.cwrites up to +0x9c).Checked
bee218d97on 2026-11-14 (head581148a0), with no merge commit; only the game's README conflicted. On that treetest_patches.py(22),test_env_switches.pyandtest_docs.pypass,docs_patches.pyleaves no diff, andlint_c.py tidyhas nothing over the baseline. I couldn't runpatch_nso.pyon the game itself for this head, because this Mac only has the decompressedmain.orig.bin, so I checked the four patch-site words against that image instead. Upstream CI is queued behind a long backlog.dm/tools/patch_nso.pyon this game's v131072 main patches all four sites (they're inmain.changed.tsv), after checking each site's original word.make -C dm/host GAME=0400486024DEC000builds;GAME=0400486024DEC000 python3 dm/ios/tools/compile_check.pyreports 263 files, 0 failed;test_patches.py,test_env_switches.pyandtest_docs.pypass.Docs
python3 dm/tools/docs_symptoms.pywas rundocs/env_switches.tsvhas a row forDM_HEAP_RETRY.