fix(oot): a full model heap hands the rest of its material block to the parent heap instead of crashing #2452

Merged
HumanBean merged 5 commits from PirateKingIsh/Longshot:fix/matblock-alloc-retry into main 2026-11-25 05:03:36 +00:00
Contributor

Summary

The game could crash when a model's own small heap ran out of room while its material block was being built (f_804566e0). That build takes memory from the heap in many places and checks none of them. host/oot_heap_retry.c already tries the block's two buffers and its GPU memory again in the heap's parents. Two things were left:

  • #2437: thread OptimizeChangeBanc writes guest 0x20, crossing Gerudo Valley's bridge as adult Link. f_8044f420 takes a 0x238-byte object from that heap for each entry of a list (tryAlloc at 0x8044f66c) and clears it without checking it. The report's crash record has lr 0x8044f684, x0 0x10 and x2 0x228, which is that clear with a null object, and x20 = 0: the heap had no room at the first object. Its log has no retry line.
  • The crash bot's thread (#81, read as it stood on 2026-11-23) has the same build crashing at the allocations next to that one: 18 reports in 11 groups, on v3.0.0, v3.0.0-rc.7 and nightlies. They are f_80443000's 0x310-byte object (0x80443e2c, 10 reports), its buffer (0x804431fc, 4) and the second of the two buffers each object gets in f_8044ed60 (0x8044f070, 4); the groups are listed under Testing. In five of those groups the log ends with the block's first buffer made in the parent, by the retry that is already there, and the crash on the next line: the retry worked and the build asked the full heap again one allocation later. None of the thread's groups has #2437's own line.

Three changes:

  • Five more allocations are tried again in the heap's parents, like the buffers: the object (0x8044f66c), its two buffers (0x8044efc4, 0x8044f070) and f_80443000's buffer and object (0x804431fc, 0x80443e2c).
  • Trying one allocation again is not enough, because the build goes on asking the same full heap, also in places that are not in that list (f_8044e020's 0x268-byte object; a 0x90-byte object f_80522050 takes before the GPU memory). With each allocation tried again alone the game still crashes, at f_8044e020's (Measurements). All of them read the heap from one place, four words on f_804558a0's stack that it makes for its one call of f_804566e0. So when one of the seven CPU allocations had to come from a parent, that parent is written there and the rest of that build takes its memory from it, the GPU memory too where it is the same heap. This follows the two buffers main already retries as well, which is where the crash reports' logs end. f_804566e0 reads its heap's free size twice to count the memory the build took (0x80456928 and 0x80457188): both reads get the model's own heap, and the second puts it back. A parent is used this way only if its reported free size covers the allocation, a 0x2000-byte margin and a heap of the model's size. HOS_GPU_ALLOC_REST=0 turns this part off.
  • I could not get the crash by play (Testing), so there is a test switch that puts a heap in that state: HOS_GPU_ALLOC_TEST_FILL=<n>[,<place>] empties up to n eligible model heaps that reach a place (the call's address; left out, the object's), through their own tryAlloc. It only fills heaps of at most 4 MB and skips heap addresses among the most recent 64 filled. To see the bug with this branch's build: HOS_GPU_ALLOC_TEST_FILL=1 HOS_GPU_ALLOC_RETRY=0 crashes while the game starts on #2437's line, and HOS_GPU_ALLOC_TEST_FILL=1,0x80443e2c HOS_GPU_ALLOC_RETRY=0 on the crash bot's most frequent one.

This description replaces the first one. The first commit (eebb1e6d) covered the object alone; the second (ef42c238) is the same fix taken to the allocations the crash reports show, after I read that thread.

Read first: the header of host/oot_heap_retry.c ("The rest of a build"), its SITES table, hos_oot_heap_retry, hos_oot_heap_rest_own and hos_oot_heap_rest_end; then OBJECT_ALLOC_SITES, REST_OWN_SITES and REST_END_SITES in nx2/oot_patches.py.

Fixes #2437 (its crash line and the state behind it; whether that reporter's session is cured only they can tell).

Testing

Tested: Windows 11, RTX 5090, NVIDIA 621.24, in the game, each start from the repository's kokiri-start save with an options file and a save folder of its own. One build for all ten starts: the first commit eebb1e6d with the second commit's changes, built before that commit (the log's longshot v3.2.0-13-geebb1e6d-dirty). The four files committed are the ones that were built; their hashes were checked before the commit. Main 9046a8d7 was merged in afterwards (206dcde9, no conflicts). Its 3 commits since 8aa5ab87 touch none of these four files; the game was not run again on the merged tree.

Nothing tried again (HOS_GPU_ALLOC_RETRY=0), one heap emptied at one place (HOS_GPU_ALLOC_TEST_FILL=1,<place>). Each start crashes while the game starts, on sead::MainThread:

  1. The object (0x8044f66c): write ..., guest 0x20, lr 0x8044f684, x0 0x10, x2 0x228, x20 0, with the first eight guest frames of #2437's report (there on OptimizeChangeBanc).
  2. f_80443000's object (0x80443e2c): write ..., guest 0, lr 0x80443e30 0x8044dcb8 0x8044cf14 0x80456d48. The crash bot's groups 3c3421252152, c384a6da8184, 9122fc95b8c9, d69d4996d756, 395dbd5efd30 (10 reports) have these frames.
  3. f_80443000's buffer (0x804431fc): write ..., guest 0x190, lr 0x80443240 0x8044dcb8 0x8044cf14 0x80456d48. Groups 7f6d6dd2100d, 93a7083f0baf, 9e83ad4976d1 (4 reports).
  4. The object's second buffer (0x8044f070): write ..., guest 0, lr 0x8044f3c0 0x8044f088 0x8044f6f4 0x8044dbd0. Groups aa6ab20813b9, 5a665be1f85a, 97435d2d0d74 (4 reports) have these four frames under one more, 0x814f2438; why this build's record does not have that frame I did not check.

Each allocation tried again alone (HOS_GPU_ALLOC_REST=0):

  1. HOS_GPU_ALLOC_TEST_FILL=150,0x8045690c HOS_GPU_ALLOC_REST=0: the first heap is emptied at the block's first buffer. The buffer, two objects, their four buffers and f_80443000's buffer and object are each made in the parent (the log has six of the seven places), then the game crashes: write ..., guest 0x20, lr 0x8044e204 0x8044dcd4 0x8044cf14 0x80456d48, which is f_8044e020's 0x268-byte object.

The fix as it ships, 150 heaps emptied at one place each (HOS_GPU_ALLOC_TEST_FILL=150,<place>), four starts:

  1. The block's first buffer (0x8045690c), the place the crash reports' logs end at.
  2. f_80443000's object (0x80443e2c).
  3. The object's second buffer (0x8044f070).
  4. The object (0x8044f66c).

In each of the four: 150 model heaps emptied (on sead::MainThread, SceneLowPriority, BaseProcCreateAndDeleteThread, BootupBackgroundWorkThread and OptimizeChangeBanc; in start 6 on engine::GraphicsModule too). The game starts, loads the save, makes Link adult and goes through 7 area changes (the control bridge's age and teleport): Gerudo Valley, Gerudo's Fortress, Gerudo Valley, Kokiri Forest, Hyrule Field, Kakariko, Gerudo Valley. No CRASH: line, closed normally. The log has the allocation made in the parent and the rest of the build handed to it, counted to 144 builds (that line is written for the first 60 and every 16th after); one build in each start, the first, on sead::MainThread, is handed over with its GPU heap.

  1. No switch: the same start and 5 area changes between Gerudo Valley and the Fortress. No oot: line in the log (nothing was tried again), no crash.

Not run in the game: the hand-over starting at f_80443000's buffer (0x804431fc) or at the object's first buffer (0x8044efc4). Both places' retries ran in start 5, and the game-free check hands a build over from each kind of place (the block's buffer, the object, an object's buffer, f_80443000's object).

Not reproduced by play: 20 crossings of Gerudo Valley's gap as adult Link (no-clip flight) on a build of main 0e32bc10 (with what became #2358), and the area changes above on this branch, never logged a failed allocation. I have no save with Epona at that bridge. The first commit's own four starts are in this PR's first comment.

The game-free check tests/test_oot_heap_retry.py fails on main's sources (f_8044f420's tryAlloc of its 0x238-byte object (0x8044f66c) is not tried again: issue 2437's crash) and passed on this branch (14 PASS lines); both were run again after the merge, against main 9046a8d7's sources and on the then head, with the same result. The whole Windows run of the checks (tests/run_all.py) on that merged head: 837 passed, 14 failed, 129 skipped. These 14 fail on main 9046a8d7 too, run there on the same PC: tests/test_auto_handheld.py, tests/test_crash_dialog.py, tests/test_dev_ab.py, tests/test_dev_build.py, tests/test_dev_migrate.py, tests/test_game_menu_mouse_buttons.py, tests/test_input_movie.py, tests/test_linux_preflight.py, tests/test_pads_after_menu.py, tests/test_perf_report.py, tests/test_portable_builder_home.py, tests/test_portable_builder_startup.py, tests/test_sdiv_overflow.py, tests/test_work_lock.py.

Still to test:

  • Linux, any GPU, in the game: a start with HOS_GPU_ALLOC_TEST_FILL=150,0x8045690c, load a save and change area a few times, expecting no crash and oot: model buffer: the rest of the build takes its memory from lines in the log (Test Farm if a maintainer wants it, or by hand).
  • The reporter of #2437, who gets the crash every time on his save (his follow-up on the issue, 2026-11-24: still on nightly-801, the same line, also when warping to Gerudo Fortress): that save on a build with this, expecting no crash; an oot: line with the rest of the build takes its memory in longshot_log.txt shows it ran. The same for anyone who gets one of the crash bot's lines above by play (by hand).

Measurements

Verdict: with a model's heap out of room at the object or at one of the three places the crash reports show, the game crashed on #2437's line or on the crash bot's. With this PR's tested build it played on at three of those four places; the fourth was not run.

Baseline: this PR's build with HOS_GPU_ALLOC_RETRY=0, which leaves these allocations as main has them (main tries none of the four again). Main has no switch that empties a heap, and the crash did not come by play. All three columns are one build, made from ef42c238's tree before it was committed.
Setup: Windows 11, RTX 5090, NVIDIA 621.24; the kokiri-start save, every setting at its default (an empty options file); the heap emptied by HOS_GPU_ALLOC_TEST_FILL; what the log says, and whether the game goes on.

A model's heap emptied at Before, HOS_GPU_ALLOC_RETRY=0 (the allocations as main has them): this PR @ ef42c238 After, HOS_GPU_ALLOC_REST=0 (each allocation alone): this PR @ ef42c238 After: this PR @ ef42c238
the object (0x8044f66c), #2437 crash at the start: write guest 0x20, lr 0x8044f684 plays: 150 heaps, 7 area changes, no crash
f_80443000's object (0x80443e2c), 10 reports crash at the start: write guest 0, lr 0x80443e30 plays: 150 heaps, 7 area changes, no crash
f_80443000's buffer (0x804431fc), 4 reports crash at the start: write guest 0x190, lr 0x80443240 not run
the object's second buffer (0x8044f070), 4 reports crash at the start: write guest 0, lr 0x8044f3c0 plays: 150 heaps, 7 area changes, no crash
the block's first buffer (0x8045690c) not run crash at the start, after nine blocks made in the parent: write guest 0x20, lr 0x8044e204 plays: 150 heaps, 7 area changes, no crash
tests/test_oot_heap_retry.py fails on main @ 8aa5ab87's sources passes

Before, the object (asset names shortened):

[hos sead::MainThread] oot: HOS_GPU_ALLOC_TEST_FILL: 5 blocks, 13 KB, taken and kept: heap 0x7fdac80020 "Model/....bfres" (36 KB, 0 KB free) is full
[hos sead::MainThread] oot: model object, 0x238 bytes from heap 0x7fdac80020, failed: not tried again (HOS_GPU_ALLOC_RETRY=0) (lr 0x8044f670)
[hos sead::MainThread] CRASH: exception 0xc0000005 (write 0x100000000020, guest 0x20) at ucrtbase.dll+0xedec0
[hos sead::MainThread] CRASH:   x0  0000000000000010  x1  0000000000000000  x2  0000000000000228  x3  0000007fdac81860
[hos sead::MainThread] CRASH:   x20 0000000000000000  x21 00000000010ff130  x22 0000000083f04f8c  x23 0000000000000000
[hos sead::MainThread] CRASH: guest backtrace: lr 0x8044f684 0x8044dbd0 0x8044cf14 0x80456d48 0x80455a70 0x83bb5a14 0x80387b00 0x80383d8c ...

Before, f_80443000's object:

[hos sead::MainThread] oot: HOS_GPU_ALLOC_TEST_FILL: 4 blocks, 11 KB, taken and kept: heap 0x7fdac80020 "Model/....bfres" (36 KB, 0 KB free) is full
[hos sead::MainThread] oot: model block, 0x310 bytes from heap 0x7fdac80020, failed: not tried again (HOS_GPU_ALLOC_RETRY=0) (lr 0x80443e30)
[hos sead::MainThread] CRASH: exception 0xc0000005 (write 0x100000000000, guest 0) at longshot.exe+0x3713e7
[hos sead::MainThread] CRASH: guest backtrace: lr 0x80443e30 0x8044dcb8 0x8044cf14 0x80456d48 0x80455a70 0x83bb5a14 0x80387b00 0x80383d8c ...

Each allocation alone (the last one made in the parent, then the crash):

[hos sead::MainThread] oot: model block, 0x310 bytes from heap 0x7fdac80020 "Model/....bfres" (36 KB, 0 KB free), failed (lr 0x80443e30)
[hos sead::MainThread] oot: model block: made in its parent heap 0x7fffff0020 "NinVirtualAddressHeap" (2870144 KB, 2127544 KB free)
[hos sead::MainThread] CRASH: exception 0xc0000005 (write 0x100000000020, guest 0x20) at ucrtbase.dll+0xedf5d
[hos sead::MainThread] CRASH: guest backtrace: lr 0x8044e204 0x8044dcd4 0x8044cf14 0x80456d48 0x80455a70 0x83bb5a14 0x80387b00 0x80383d8c ...

After, f_80443000's object (the first of the 150, and the last count line):

[hos sead::MainThread] oot: HOS_GPU_ALLOC_TEST_FILL: 4 blocks, 11 KB, taken and kept: heap 0x7fdac80020 "Model/....bfres" (36 KB, 0 KB free) is full
[hos sead::MainThread] oot: model block, 0x310 bytes from heap 0x7fdac80020 "Model/....bfres" (36 KB, 0 KB free), failed (lr 0x80443e30)
[hos sead::MainThread] oot: model block: made in its parent heap 0x7fffff0020 "NinVirtualAddressHeap" (2870144 KB, 2127840 KB free)
[hos sead::MainThread] oot: heap-full retries so far: model block (0x80443e2c) 1 blocks, 0 KB in parent heaps
[hos sead::MainThread] oot: model block: the rest of the build takes its memory, the GPU's too, from heap 0x7fffff0020 "NinVirtualAddressHeap" (2870144 KB, 2127840 KB free) (1 builds so far)
[hos OptimizeChangeBanc] oot: model block: the rest of the build takes its memory from heap 0x7fffff0020 "NinVirtualAddressHeap" (2870144 KB, 1456788 KB free) (144 builds so far)

Not measured: frame time. The changed code runs where material blocks are built. With no switch set an area change took 3.26 to 3.41 s to Gerudo Valley (3 visits) and 3.49 to 3.75 s to the Fortress (2), against 3.33 to 3.39 s and 3.49 to 3.84 s on the first commit's build over the same route (from sending the teleport to the bridge reporting the new map; other programs were running on the PC during the second commit's start: not a controlled comparison).

Risks

  • It acts only when a model's heap has no room for one of the seven allocations. Before, that was a crash, at once or at one of the build's next allocations. From then on that build's memory comes from the parent heap (NinVirtualAddressHeap in my runs: the log's 2870144 KB, with 1452884 to 2132496 KB free over these starts). The blocks I followed to their frees are freed by address (f_8021dea0, read in the lifted code, not traced in a run): the block's two buffers, the objects, their two buffers, f_80443000's buffer and object. The other blocks such a build takes from the parent I did not follow. If one were never freed, each build that met a full heap would leave it in the parent: my estimate is at most about its model heap's size, not measured (the heaps emptied in my starts are 5 KB to 3.8 MB, half of them 112 KB or less). The log cannot show such a leak in my runs: the parent's free size in the the rest of the build takes its memory from heap ... (N KB free) lines falls by 620000 to 675000 KB between a start's first such line and its last, and loading the save and the areas takes its memory from the same heap. I did not run a long session.
  • Not covered: a build whose first failing allocation is not one of the seven (f_8044e020's 0x268-byte object, f_8017dd60's and f_8017ed80's allocations, f_80522050's 0x90-byte object, and the other way f_8044f420 and f_8044ed60 get memory, f_8005eca0). After one of the seven has failed, these take from the parent too. The crash bot's thread also has lines inside this build that this PR does not claim: 0x80456cec (49 reports, 48 of them on v3.0.0-rc.7; not read), 0x80293bc8 under 0x80457138 (15 reports; an indirect call near the end of f_804566e0, its cause not found), and deeper ones under f_80443000 and f_8044cb30 that I did not read (0x80444d10 under 0x80443c28: 4 reports; 0x80447cc0 under 0x80443d00: 3; five single ones).
  • Off: HOS_GPU_ALLOC_REST=0 (the hand-over alone) or HOS_GPU_ALLOC_RETRY=0 (every retry, as shipped).
  • Cost: f_8044f420 and f_80443000 are no longer given register locals, because nx2/oot_patches.py now names an address in each. They are the 661st and the 425th of the hot list's 680 (hottest first); at least 17 other functions of that list are named in that file already. f_8044ed60 is not on the list. The frame-time effect is not measured (Measurements).
  • Nothing changes for saves, longshot_options.ini or the caches.

Checklist

Ready for review

  • One topic, on current main; the title is a Conventional Commit.
  • Tested on my own PC, in the game for a change the game runs, as Testing says.
  • mise run test passes (any failure that also fails on main is named).
  • Measured against main, or Measurements says why there is nothing to measure.
  • No game files, build output or hand-edited generated files; third_party/ untouched; nothing GPL-incompatible.

When it applies

  • A fix: a game-free test that fails on main and passes here.
  • A switch added or changed: it ships at the default the measurements chose, with its row in gpu/vk/switches.def. HOS_GPU_ALLOC_REST is on by default (off is start 5 above); HOS_GPU_ALLOC_TEST_FILL is a test switch, off by default; HOS_GPU_ALLOC_TEST_FAIL (a test) takes a third number.
  • A check under tests/ that reads changed source is updated, not weakened.
  • Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths. Built on Windows here; Linux is CI's to build (the new code adds no path and uses _Thread_local as host/hos_main.c does).
  • AI assistance recorded with Assisted-by: / Co-Authored-By: trailers. Claude found the cause, read the crash reports, wrote the change and the test and drove the game in the runs; I built and ran everything on my PC.

Ready to merge

  • Everything in Still to test has run, its results in Tested.
  • Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers").
  • Approved in review, every comment answered.
  • CI passes on the head; on current main, measured again or a comment says why the numbers still hold.
## Summary The game could crash when a model's own small heap ran out of room while its material block was being built (f_804566e0). That build takes memory from the heap in many places and checks none of them. `host/oot_heap_retry.c` already tries the block's two buffers and its GPU memory again in the heap's parents. Two things were left: - #2437: thread OptimizeChangeBanc writes guest 0x20, crossing Gerudo Valley's bridge as adult Link. f_8044f420 takes a 0x238-byte object from that heap for each entry of a list (tryAlloc at 0x8044f66c) and clears it without checking it. The report's crash record has lr 0x8044f684, x0 0x10 and x2 0x228, which is that clear with a null object, and x20 = 0: the heap had no room at the first object. Its log has no retry line. - The crash bot's thread (#81, read as it stood on 2026-11-23) has the same build crashing at the allocations next to that one: 18 reports in 11 groups, on v3.0.0, v3.0.0-rc.7 and nightlies. They are f_80443000's 0x310-byte object (0x80443e2c, 10 reports), its buffer (0x804431fc, 4) and the second of the two buffers each object gets in f_8044ed60 (0x8044f070, 4); the groups are listed under Testing. In five of those groups the log ends with the block's first buffer made in the parent, by the retry that is already there, and the crash on the next line: the retry worked and the build asked the full heap again one allocation later. None of the thread's groups has #2437's own line. Three changes: - Five more allocations are tried again in the heap's parents, like the buffers: the object (0x8044f66c), its two buffers (0x8044efc4, 0x8044f070) and f_80443000's buffer and object (0x804431fc, 0x80443e2c). - Trying one allocation again is not enough, because the build goes on asking the same full heap, also in places that are not in that list (f_8044e020's 0x268-byte object; a 0x90-byte object f_80522050 takes before the GPU memory). With each allocation tried again alone the game still crashes, at f_8044e020's (Measurements). All of them read the heap from one place, four words on f_804558a0's stack that it makes for its one call of f_804566e0. So when one of the seven CPU allocations had to come from a parent, that parent is written there and the rest of that build takes its memory from it, the GPU memory too where it is the same heap. This follows the two buffers main already retries as well, which is where the crash reports' logs end. f_804566e0 reads its heap's free size twice to count the memory the build took (0x80456928 and 0x80457188): both reads get the model's own heap, and the second puts it back. A parent is used this way only if its reported free size covers the allocation, a 0x2000-byte margin and a heap of the model's size. `HOS_GPU_ALLOC_REST=0` turns this part off. - I could not get the crash by play (Testing), so there is a test switch that puts a heap in that state: `HOS_GPU_ALLOC_TEST_FILL=<n>[,<place>]` empties up to n eligible model heaps that reach a place (the call's address; left out, the object's), through their own tryAlloc. It only fills heaps of at most 4 MB and skips heap addresses among the most recent 64 filled. To see the bug with this branch's build: `HOS_GPU_ALLOC_TEST_FILL=1 HOS_GPU_ALLOC_RETRY=0` crashes while the game starts on #2437's line, and `HOS_GPU_ALLOC_TEST_FILL=1,0x80443e2c HOS_GPU_ALLOC_RETRY=0` on the crash bot's most frequent one. This description replaces the first one. The first commit (eebb1e6d) covered the object alone; the second (ef42c238) is the same fix taken to the allocations the crash reports show, after I read that thread. Read first: the header of `host/oot_heap_retry.c` ("The rest of a build"), its `SITES` table, `hos_oot_heap_retry`, `hos_oot_heap_rest_own` and `hos_oot_heap_rest_end`; then `OBJECT_ALLOC_SITES`, `REST_OWN_SITES` and `REST_END_SITES` in `nx2/oot_patches.py`. Fixes #2437 (its crash line and the state behind it; whether that reporter's session is cured only they can tell). ## Testing **Tested:** Windows 11, RTX 5090, NVIDIA 621.24, in the game, each start from the repository's kokiri-start save with an options file and a save folder of its own. One build for all ten starts: the first commit eebb1e6d with the second commit's changes, built before that commit (the log's `longshot v3.2.0-13-geebb1e6d-dirty`). The four files committed are the ones that were built; their hashes were checked before the commit. Main 9046a8d7 was merged in afterwards (206dcde9, no conflicts). Its 3 commits since 8aa5ab87 touch none of these four files; the game was not run again on the merged tree. Nothing tried again (`HOS_GPU_ALLOC_RETRY=0`), one heap emptied at one place (`HOS_GPU_ALLOC_TEST_FILL=1,<place>`). Each start crashes while the game starts, on sead::MainThread: 1. The object (0x8044f66c): `write ..., guest 0x20`, lr 0x8044f684, x0 0x10, x2 0x228, x20 0, with the first eight guest frames of #2437's report (there on OptimizeChangeBanc). 2. f_80443000's object (0x80443e2c): `write ..., guest 0`, lr 0x80443e30 0x8044dcb8 0x8044cf14 0x80456d48. The crash bot's groups `3c3421252152`, `c384a6da8184`, `9122fc95b8c9`, `d69d4996d756`, `395dbd5efd30` (10 reports) have these frames. 3. f_80443000's buffer (0x804431fc): `write ..., guest 0x190`, lr 0x80443240 0x8044dcb8 0x8044cf14 0x80456d48. Groups `7f6d6dd2100d`, `93a7083f0baf`, `9e83ad4976d1` (4 reports). 4. The object's second buffer (0x8044f070): `write ..., guest 0`, lr 0x8044f3c0 0x8044f088 0x8044f6f4 0x8044dbd0. Groups `aa6ab20813b9`, `5a665be1f85a`, `97435d2d0d74` (4 reports) have these four frames under one more, 0x814f2438; why this build's record does not have that frame I did not check. Each allocation tried again alone (`HOS_GPU_ALLOC_REST=0`): 5. `HOS_GPU_ALLOC_TEST_FILL=150,0x8045690c HOS_GPU_ALLOC_REST=0`: the first heap is emptied at the block's first buffer. The buffer, two objects, their four buffers and f_80443000's buffer and object are each made in the parent (the log has six of the seven places), then the game crashes: `write ..., guest 0x20`, lr 0x8044e204 0x8044dcd4 0x8044cf14 0x80456d48, which is f_8044e020's 0x268-byte object. The fix as it ships, 150 heaps emptied at one place each (`HOS_GPU_ALLOC_TEST_FILL=150,<place>`), four starts: 6. The block's first buffer (0x8045690c), the place the crash reports' logs end at. 7. f_80443000's object (0x80443e2c). 8. The object's second buffer (0x8044f070). 9. The object (0x8044f66c). In each of the four: 150 model heaps emptied (on sead::MainThread, SceneLowPriority, BaseProcCreateAndDeleteThread, BootupBackgroundWorkThread and OptimizeChangeBanc; in start 6 on engine::GraphicsModule too). The game starts, loads the save, makes Link adult and goes through 7 area changes (the control bridge's `age` and `teleport`): Gerudo Valley, Gerudo's Fortress, Gerudo Valley, Kokiri Forest, Hyrule Field, Kakariko, Gerudo Valley. No `CRASH:` line, closed normally. The log has the allocation made in the parent and the rest of the build handed to it, counted to 144 builds (that line is written for the first 60 and every 16th after); one build in each start, the first, on sead::MainThread, is handed over with its GPU heap. 10. No switch: the same start and 5 area changes between Gerudo Valley and the Fortress. No `oot:` line in the log (nothing was tried again), no crash. Not run in the game: the hand-over starting at f_80443000's buffer (0x804431fc) or at the object's first buffer (0x8044efc4). Both places' retries ran in start 5, and the game-free check hands a build over from each kind of place (the block's buffer, the object, an object's buffer, f_80443000's object). Not reproduced by play: 20 crossings of Gerudo Valley's gap as adult Link (no-clip flight) on a build of main 0e32bc10 (with what became #2358), and the area changes above on this branch, never logged a failed allocation. I have no save with Epona at that bridge. The first commit's own four starts are in this PR's first comment. The game-free check `tests/test_oot_heap_retry.py` fails on main's sources (`f_8044f420's tryAlloc of its 0x238-byte object (0x8044f66c) is not tried again: issue 2437's crash`) and passed on this branch (14 PASS lines); both were run again after the merge, against main 9046a8d7's sources and on the then head, with the same result. The whole Windows run of the checks (`tests/run_all.py`) on that merged head: 837 passed, 14 failed, 129 skipped. These 14 fail on main 9046a8d7 too, run there on the same PC: `tests/test_auto_handheld.py`, `tests/test_crash_dialog.py`, `tests/test_dev_ab.py`, `tests/test_dev_build.py`, `tests/test_dev_migrate.py`, `tests/test_game_menu_mouse_buttons.py`, `tests/test_input_movie.py`, `tests/test_linux_preflight.py`, `tests/test_pads_after_menu.py`, `tests/test_perf_report.py`, `tests/test_portable_builder_home.py`, `tests/test_portable_builder_startup.py`, `tests/test_sdiv_overflow.py`, `tests/test_work_lock.py`. **Still to test:** - Linux, any GPU, in the game: a start with `HOS_GPU_ALLOC_TEST_FILL=150,0x8045690c`, load a save and change area a few times, expecting no crash and `oot: model buffer: the rest of the build takes its memory from` lines in the log (Test Farm if a maintainer wants it, or by hand). - The reporter of #2437, who gets the crash every time on his save (his follow-up on the issue, 2026-11-24: still on nightly-801, the same line, also when warping to Gerudo Fortress): that save on a build with this, expecting no crash; an `oot:` line with `the rest of the build takes its memory` in `longshot_log.txt` shows it ran. The same for anyone who gets one of the crash bot's lines above by play (by hand). ## Measurements **Verdict:** with a model's heap out of room at the object or at one of the three places the crash reports show, the game crashed on #2437's line or on the crash bot's. With this PR's tested build it played on at three of those four places; the fourth was not run. Baseline: this PR's build with `HOS_GPU_ALLOC_RETRY=0`, which leaves these allocations as main has them (main tries none of the four again). Main has no switch that empties a heap, and the crash did not come by play. All three columns are one build, made from ef42c238's tree before it was committed. Setup: Windows 11, RTX 5090, NVIDIA 621.24; the kokiri-start save, every setting at its default (an empty options file); the heap emptied by `HOS_GPU_ALLOC_TEST_FILL`; what the log says, and whether the game goes on. | A model's heap emptied at | Before, `HOS_GPU_ALLOC_RETRY=0` (the allocations as main has them): this PR @ ef42c238 | After, `HOS_GPU_ALLOC_REST=0` (each allocation alone): this PR @ ef42c238 | After: this PR @ ef42c238 | |---|---|---|---| | the object (0x8044f66c), #2437 | crash at the start: write guest 0x20, lr 0x8044f684 | | plays: 150 heaps, 7 area changes, no crash | | f_80443000's object (0x80443e2c), 10 reports | crash at the start: write guest 0, lr 0x80443e30 | | plays: 150 heaps, 7 area changes, no crash | | f_80443000's buffer (0x804431fc), 4 reports | crash at the start: write guest 0x190, lr 0x80443240 | | not run | | the object's second buffer (0x8044f070), 4 reports | crash at the start: write guest 0, lr 0x8044f3c0 | | plays: 150 heaps, 7 area changes, no crash | | the block's first buffer (0x8045690c) | not run | crash at the start, after nine blocks made in the parent: write guest 0x20, lr 0x8044e204 | plays: 150 heaps, 7 area changes, no crash | | `tests/test_oot_heap_retry.py` | fails on main @ 8aa5ab87's sources | | passes | Before, the object (asset names shortened): ``` [hos sead::MainThread] oot: HOS_GPU_ALLOC_TEST_FILL: 5 blocks, 13 KB, taken and kept: heap 0x7fdac80020 "Model/....bfres" (36 KB, 0 KB free) is full [hos sead::MainThread] oot: model object, 0x238 bytes from heap 0x7fdac80020, failed: not tried again (HOS_GPU_ALLOC_RETRY=0) (lr 0x8044f670) [hos sead::MainThread] CRASH: exception 0xc0000005 (write 0x100000000020, guest 0x20) at ucrtbase.dll+0xedec0 [hos sead::MainThread] CRASH: x0 0000000000000010 x1 0000000000000000 x2 0000000000000228 x3 0000007fdac81860 [hos sead::MainThread] CRASH: x20 0000000000000000 x21 00000000010ff130 x22 0000000083f04f8c x23 0000000000000000 [hos sead::MainThread] CRASH: guest backtrace: lr 0x8044f684 0x8044dbd0 0x8044cf14 0x80456d48 0x80455a70 0x83bb5a14 0x80387b00 0x80383d8c ... ``` Before, f_80443000's object: ``` [hos sead::MainThread] oot: HOS_GPU_ALLOC_TEST_FILL: 4 blocks, 11 KB, taken and kept: heap 0x7fdac80020 "Model/....bfres" (36 KB, 0 KB free) is full [hos sead::MainThread] oot: model block, 0x310 bytes from heap 0x7fdac80020, failed: not tried again (HOS_GPU_ALLOC_RETRY=0) (lr 0x80443e30) [hos sead::MainThread] CRASH: exception 0xc0000005 (write 0x100000000000, guest 0) at longshot.exe+0x3713e7 [hos sead::MainThread] CRASH: guest backtrace: lr 0x80443e30 0x8044dcb8 0x8044cf14 0x80456d48 0x80455a70 0x83bb5a14 0x80387b00 0x80383d8c ... ``` Each allocation alone (the last one made in the parent, then the crash): ``` [hos sead::MainThread] oot: model block, 0x310 bytes from heap 0x7fdac80020 "Model/....bfres" (36 KB, 0 KB free), failed (lr 0x80443e30) [hos sead::MainThread] oot: model block: made in its parent heap 0x7fffff0020 "NinVirtualAddressHeap" (2870144 KB, 2127544 KB free) [hos sead::MainThread] CRASH: exception 0xc0000005 (write 0x100000000020, guest 0x20) at ucrtbase.dll+0xedf5d [hos sead::MainThread] CRASH: guest backtrace: lr 0x8044e204 0x8044dcd4 0x8044cf14 0x80456d48 0x80455a70 0x83bb5a14 0x80387b00 0x80383d8c ... ``` After, f_80443000's object (the first of the 150, and the last count line): ``` [hos sead::MainThread] oot: HOS_GPU_ALLOC_TEST_FILL: 4 blocks, 11 KB, taken and kept: heap 0x7fdac80020 "Model/....bfres" (36 KB, 0 KB free) is full [hos sead::MainThread] oot: model block, 0x310 bytes from heap 0x7fdac80020 "Model/....bfres" (36 KB, 0 KB free), failed (lr 0x80443e30) [hos sead::MainThread] oot: model block: made in its parent heap 0x7fffff0020 "NinVirtualAddressHeap" (2870144 KB, 2127840 KB free) [hos sead::MainThread] oot: heap-full retries so far: model block (0x80443e2c) 1 blocks, 0 KB in parent heaps [hos sead::MainThread] oot: model block: the rest of the build takes its memory, the GPU's too, from heap 0x7fffff0020 "NinVirtualAddressHeap" (2870144 KB, 2127840 KB free) (1 builds so far) [hos OptimizeChangeBanc] oot: model block: the rest of the build takes its memory from heap 0x7fffff0020 "NinVirtualAddressHeap" (2870144 KB, 1456788 KB free) (144 builds so far) ``` Not measured: frame time. The changed code runs where material blocks are built. With no switch set an area change took 3.26 to 3.41 s to Gerudo Valley (3 visits) and 3.49 to 3.75 s to the Fortress (2), against 3.33 to 3.39 s and 3.49 to 3.84 s on the first commit's build over the same route (from sending the teleport to the bridge reporting the new map; other programs were running on the PC during the second commit's start: not a controlled comparison). ## Risks - It acts only when a model's heap has no room for one of the seven allocations. Before, that was a crash, at once or at one of the build's next allocations. From then on that build's memory comes from the parent heap (NinVirtualAddressHeap in my runs: the log's 2870144 KB, with 1452884 to 2132496 KB free over these starts). The blocks I followed to their frees are freed by address (f_8021dea0, read in the lifted code, not traced in a run): the block's two buffers, the objects, their two buffers, f_80443000's buffer and object. The other blocks such a build takes from the parent I did not follow. If one were never freed, each build that met a full heap would leave it in the parent: my estimate is at most about its model heap's size, not measured (the heaps emptied in my starts are 5 KB to 3.8 MB, half of them 112 KB or less). The log cannot show such a leak in my runs: the parent's free size in the `the rest of the build takes its memory from heap ... (N KB free)` lines falls by 620000 to 675000 KB between a start's first such line and its last, and loading the save and the areas takes its memory from the same heap. I did not run a long session. - Not covered: a build whose first failing allocation is not one of the seven (f_8044e020's 0x268-byte object, f_8017dd60's and f_8017ed80's allocations, f_80522050's 0x90-byte object, and the other way f_8044f420 and f_8044ed60 get memory, f_8005eca0). After one of the seven has failed, these take from the parent too. The crash bot's thread also has lines inside this build that this PR does not claim: 0x80456cec (49 reports, 48 of them on v3.0.0-rc.7; not read), 0x80293bc8 under 0x80457138 (15 reports; an indirect call near the end of f_804566e0, its cause not found), and deeper ones under f_80443000 and f_8044cb30 that I did not read (0x80444d10 under 0x80443c28: 4 reports; 0x80447cc0 under 0x80443d00: 3; five single ones). - Off: `HOS_GPU_ALLOC_REST=0` (the hand-over alone) or `HOS_GPU_ALLOC_RETRY=0` (every retry, as shipped). - Cost: f_8044f420 and f_80443000 are no longer given register locals, because `nx2/oot_patches.py` now names an address in each. They are the 661st and the 425th of the hot list's 680 (hottest first); at least 17 other functions of that list are named in that file already. f_8044ed60 is not on the list. The frame-time effect is not measured (Measurements). - Nothing changes for saves, `longshot_options.ini` or the caches. ## Checklist ### Ready for review - [x] One topic, on current `main`; the title is a Conventional Commit. - [x] Tested on my own PC, in the game for a change the game runs, as Testing says. - [ ] `mise run test` passes (any failure that also fails on `main` is named). - [x] Measured against `main`, or Measurements says why there is nothing to measure. - [x] No game files, build output or hand-edited generated files; `third_party/` untouched; nothing GPL-incompatible. ### When it applies - [x] A fix: a game-free test that fails on `main` and passes here. - [x] A switch added or changed: it ships at the default the measurements chose, with its row in `gpu/vk/switches.def`. `HOS_GPU_ALLOC_REST` is on by default (off is start 5 above); `HOS_GPU_ALLOC_TEST_FILL` is a test switch, off by default; `HOS_GPU_ALLOC_TEST_FAIL` (a test) takes a third number. - [x] A check under `tests/` that reads changed source is updated, not weakened. - [ ] Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths. Built on Windows here; Linux is CI's to build (the new code adds no path and uses `_Thread_local` as `host/hos_main.c` does). - [x] AI assistance recorded with `Assisted-by:` / `Co-Authored-By:` trailers. Claude found the cause, read the crash reports, wrote the change and the test and drove the game in the runs; I built and ran everything on my PC. ### Ready to merge - [ ] Everything in Still to test has run, its results in Tested. - [ ] Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers"). - [ ] Approved in review, every comment answered. - [ ] CI passes on the head; on current `main`, measured again or a comment says why the numbers still hold.
fix(oot): a full model heap hands the rest of its material block to the parent heap instead of crashing
Some checks failed
Website / Website on Cloudflare (pull_request_target) Has been skipped
PR description / Description follows the template (pull_request_target) Successful in 9s
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
eebb1e6d65
Issue 2437: thread OptimizeChangeBanc writes guest 0x20 (lr 0x8044f684, x0 0x10, x2 0x228) crossing Gerudo Valley's
bridge as adult Link. f_8044f420 takes a 0x238-byte object for each entry of its list from the model's own heap
(tryAlloc at 0x8044f66c) and clears it without a check; the record's x20 is 0, so the heap had no room at the first
one. host/oot_heap_retry.c tried the material block's two buffers and its GPU memory again in the heap's parents, not
this object.

- The object is tried again in the heap's parents like the buffers (hos_oot_heap_retry_object).
- The build goes on taking memory from the same heap, unchecked too (the object's two buffers in f_8044ed60, then
  f_80443000 and f_8044e020), so the parent that had room is written to the heaps' holder (f_804558a0's four words on
  its stack, read at each allocation) and the rest of the build takes its memory there; the GPU heap goes with it where
  it is the same heap. f_804566e0's last read of its heap (0x80457188, its memory count) gets the build's own heap back
  first (hos_oot_heap_rest_end). HOS_GPU_ALLOC_REST=0 turns the hand-over off.
- HOS_GPU_ALLOC_TEST_FILL=<n> (a test) empties the first n model heaps that reach the object's place, through their
  own tryAlloc: the state the report's heap was in. HOS_GPU_ALLOC_TEST_FAIL takes a third number, for the object.
- tests/test_oot_heap_retry.py: the two new places in the lifted text, the object's retry, the hand-over and its end
  (a GPU heap that is the same heap, a holder on a stack below the image, a parent that runs out in turn), the fill.

Fixes #2437

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_01AkPeBa76RtpdoF8gThSSue
Author
Contributor

Tested on my PC (Windows 11, RTX 5090, NVIDIA 621.24), in the game, from the repository's kokiri-start save. The crash did not come by play here, so a model's heap was emptied for real with the new test switch. With HOS_GPU_ALLOC_TEST_FILL=1 HOS_GPU_ALLOC_RETRY=0 the game crashes while it starts on the report's line (write ..., guest 0x20, lr 0x8044f684). With HOS_GPU_ALLOC_TEST_FILL=150 and nothing else it starts, loads the save and goes through 10 area changes as adult Link (Gerudo Valley and Fortress, Kokiri Forest, Hyrule Field, Kakariko) with no crash; the log shows each emptied heap's build finished in the parent heap. With no switch set the same build plays the same route and its log has no oot: line. The game-free check fails on main's sources and passes on this branch.

Tested on my PC (Windows 11, RTX 5090, NVIDIA 621.24), in the game, from the repository's kokiri-start save. The crash did not come by play here, so a model's heap was emptied for real with the new test switch. With `HOS_GPU_ALLOC_TEST_FILL=1 HOS_GPU_ALLOC_RETRY=0` the game crashes while it starts on the report's line (`write ..., guest 0x20`, lr 0x8044f684). With `HOS_GPU_ALLOC_TEST_FILL=150` and nothing else it starts, loads the save and goes through 10 area changes as adult Link (Gerudo Valley and Fortress, Kokiri Forest, Hyrule Field, Kakariko) with no crash; the log shows each emptied heap's build finished in the parent heap. With no switch set the same build plays the same route and its log has no `oot:` line. The game-free check fails on main's sources and passes on this branch.
PirateKingIsh changed title from fix(oot): a full model heap hands the rest of its material block to the parent heap instead of crashing to WIP(oot): a full model heap hands the rest of its material block to the parent heap instead of crashing 2026-11-24 12:33:31 +00:00
PirateKingIsh changed title from WIP(oot): a full model heap hands the rest of its material block to the parent heap instead of crashing to WIP: a full model heap hands the rest of its material block to the parent heap instead of crashing 2026-11-24 12:33:45 +00:00
fix(oot): the material block's other unchecked allocations hand a full heap's build to the parent too
Some checks failed
PR description / Description follows the template (pull_request_target) Successful in 18s
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
ef42c2383b
The crash bot's thread (issue 81, as it stood on 2026-11-23) has the build of a material block (f_804566e0) crashing
at the allocations next to issue 2437's object, 18 reports in 11 groups on v3.0.0, rc.7 and nightlies: f_80443000's
0x310-byte object (write guest 0, lr 0x80443e30; 10 reports), its buffer (write guest 0x190, lr 0x80443240; 4) and the
second of the two buffers each object gets in f_8044ed60 (write guest 0, lr 0x8044f3c0 under 0x8044f088; 4). In five
of those groups the log ends with the block's first buffer made in the parent, by the retry main has, and the crash
on the next line: the build asked the full heap again.

- Tried again in the heap's parents, like the object: its two buffers (0x8044efc4, 0x8044f070) and f_80443000's
  buffer and object (0x804431fc, 0x80443e2c). One function for the seven CPU allocations (hos_oot_heap_retry) and
  one table of their places (SITES).
- The hand-over of the rest of the build to that parent follows any of the seven, the two buffers main already
  tried again included, not the object alone (as before, only into a parent with room for a heap of the model's
  size). f_804566e0's first read of its heap's free size (0x80456928, just after the first buffer) gets the build's
  own heap as well (hos_oot_heap_rest_own), so its count of the build's memory compares one heap with itself.
- HOS_GPU_ALLOC_TEST_FILL=<n>[,<place>]: the place whose heaps are emptied can be named.
  HOS_GPU_ALLOC_TEST_FAIL's third number is for the five other CPU allocations.
- tests/test_oot_heap_retry.py: the eleven places in the lifted text, each with the holder it reads, a hand-over
  from each kind of place, the fill at a named place.

In the game (Windows 11, RTX 5090): with nothing tried again and a heap emptied at 0x80443e2c, 0x804431fc or
0x8044f070 the game crashes on those three lines; with each allocation tried again alone it crashes at f_8044e020's
0x268-byte object, which is not in the list; with the hand-over and 150 heaps emptied at one of four places it plays
through 7 area changes.

Refs #2437

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_01AkPeBa76RtpdoF8gThSSue
PirateKingIsh changed title from WIP: a full model heap hands the rest of its material block to the parent heap instead of crashing to fix(oot): a full model heap hands the rest of its material block to the parent heap instead of crashing 2026-11-24 12:41:33 +00:00
Author
Contributor

I pushed a second commit (ef42c238) and replaced the description.

After opening this I read the crash bot's thread (#81) for this build. None of its groups has #2437's own line, but 18 reports in 11 groups crash at the allocations right next to it: f_80443000's object and its buffer, and the second buffer of the object this PR started with. In five of those groups the log ends with the buffer retry that main already has, working, one line before the crash. The first commit covered only the object, so it would not have helped those players.

The second commit gives those allocations the same retry, and the hand-over of the rest of the build to the parent heap now follows any of them, the two buffers main already tries again included.

Tested in the game on my PC (Windows 11, RTX 5090, NVIDIA 621.24), ten starts, as the description lists them: with the retry off and a heap emptied at each of those places, the game crashes on the crash bot's lines (the same frames; for the second buffer the bot's reports have one more frame on top); with the fix on and 150 heaps emptied, it starts, loads the save and goes through 7 area changes with no crash, at each of four places. With no switch set the log has no oot: line.

What it does not claim is in Risks: the 15-report line under 0x80457138 and the deeper ones under f_80443000 are not understood or not read.

I pushed a second commit (ef42c238) and replaced the description. After opening this I read the crash bot's thread (#81) for this build. None of its groups has #2437's own line, but 18 reports in 11 groups crash at the allocations right next to it: f_80443000's object and its buffer, and the second buffer of the object this PR started with. In five of those groups the log ends with the buffer retry that main already has, working, one line before the crash. The first commit covered only the object, so it would not have helped those players. The second commit gives those allocations the same retry, and the hand-over of the rest of the build to the parent heap now follows any of them, the two buffers main already tries again included. Tested in the game on my PC (Windows 11, RTX 5090, NVIDIA 621.24), ten starts, as the description lists them: with the retry off and a heap emptied at each of those places, the game crashes on the crash bot's lines (the same frames; for the second buffer the bot's reports have one more frame on top); with the fix on and 150 heaps emptied, it starts, loads the save and goes through 7 area changes with no crash, at each of four places. With no switch set the log has no `oot:` line. What it does not claim is in Risks: the 15-report line under 0x80457138 and the deeper ones under f_80443000 are not understood or not read.
Merge main 9046a8d7 into fix/matblock-alloc-retry
Some checks failed
Website / Website on Cloudflare (pull_request_target) Has been skipped
Website / Website builds (pull_request_target) Has been skipped
Website / Website preview, build (pull_request_target) Has been skipped
Website / Website preview, upload (pull_request_target) Has been skipped
PR description / Description follows the template (pull_request_target) Successful in 5s
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
Website / Website on Cloudflare (pull_request) Has been cancelled
Website / Website builds (pull_request) Has been cancelled
Website / Website preview, build (pull_request) Has been cancelled
Website / Website preview, upload (pull_request) Has been cancelled
206dcde9a0
Main has 3 commits since 8aa5ab87, where this branch started; none touches gpu/vk/switches.def,
host/oot_heap_retry.c, nx2/oot_patches.py or tests/test_oot_heap_retry.py. No conflicts. A plain merge: the two
commits of pull request 2452 are as they were pushed.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_01AkPeBa76RtpdoF8gThSSue
Author
Contributor

Merged main 9046a8d7 in (206dcde9): a plain merge, no conflicts, no force-push. Main's 3 commits since this branch started touch none of its four files. The checks were run again on the merged head: 837 passed, 14 failed, 129 skipped; the 14 that fail also fail on main 9046a8d7. The game was not run again on the merged tree; the description says so.

One more thing for whoever reviews this. The reporter of #2437 followed up on the issue on 2026-11-24: it crashes every time on his save, also when he warps to Gerudo Fortress, still on nightly-801, with the same record (OptimizeChangeBanc, guest 0x20, lr 0x8044f684). That is the line this pull request's first commit is about, so his save on a build with this branch is the direct test I could not do myself.

Merged main 9046a8d7 in (206dcde9): a plain merge, no conflicts, no force-push. Main's 3 commits since this branch started touch none of its four files. The checks were run again on the merged head: 837 passed, 14 failed, 129 skipped; the 14 that fail also fail on main 9046a8d7. The game was not run again on the merged tree; the description says so. One more thing for whoever reviews this. The reporter of #2437 followed up on the issue on 2026-11-24: it crashes every time on his save, also when he warps to Gerudo Fortress, still on nightly-801, with the same record (OptimizeChangeBanc, guest 0x20, lr 0x8044f684). That is the line this pull request's first commit is about, so his save on a build with this branch is the direct test I could not do myself.
Member
@review
BeanBot requested changes 2026-11-25 02:14:22 +00:00
Dismissed
BeanBot left a comment

Recommendation: Request changes. The retry can still leave the rest of a build on a full heap even when a higher parent has room, and its new shared state has data races. The test also commits passages shaped from lifted game code, contrary to the repository’s game-data rule.

The change retries five more material-block allocations and moves subsequent allocations to a parent heap. Forced-full Windows runs show the approach can avoid the reported crashes, but recovery is incomplete in one parent-heap case and its memory lifetime and cross-platform behavior need further validation.

Blocking (2): must change before merging.

  1. L1 host/oot_heap_retry.c:342: The retry stops at the first parent that can satisfy the individual allocation, even if that parent cannot support the rest of the build. (more on the line) Do: Select a parent suitable for the whole hand-over before allocating the retried block, continuing up the chain when the nearest parent is too small, and add a test with a small intermediate parent and a sufficiently large ancestor.
  2. L4 tests/test_oot_heap_retry.py:476: The new fixture includes passages presented as lifted game instructions, which the repository prohibits committing. (more on the line) Do: Replace the passages with independently authored synthetic fixtures containing only the minimal patch anchors and fabricated surrounding behavior, and remove the sampled game-derived sequences from the commits.

Should fix (2): not blocking, but worth doing before merging.

  • L2 host/oot_heap_retry.c:93: The new cached switch value is read and written without synchronization across game threads. (more on the line) Do: Initialize and publish the cached value with atomics or a once primitive, or read the switch without a shared mutable cache.
  • L3 host/oot_heap_retry.c:295: The test-fill counter is read outside its lock while other threads decrement it under the lock; volatile does not make those accesses atomic. (more on the line) Do: Use atomic accesses consistently for left, including its decrement, or perform every access under the same lock.

Testing before merging (2) (runs on the systems it can change; it doesn't hold the recommendation)

  • L5 host/oot_heap_retry.c:348: The new parent-heap hand-over needs a longer lifetime check and runs on the supported platforms it affects. (more on the line) Do: Run repeated model rebuilds and area changes on Linux and representative Tier 1 systems, tracking parent-heap use after the models are released; also test the reporter’s reproducible save if available. (@fix does its part first: Add accounting for the allocations made after hand-over so a repeated-load run can distinguish retained build memory from unrelated parent-heap use.)
  • L6 nx2/oot_patches.py:1496: The hot functions now lose register-local optimization and execute additional hooks, but their frame-time cost has not been measured. (more on the line) Do: Compare the base and head with repeated interleaved runs in material-heavy gameplay, recording frame-time distribution and 1% lows. (@fix does its part first: Restructure the hook insertion so these functions can retain register-local optimization, or avoid the per-allocation test hook in ordinary builds.)

@fix can do L1, L2, L3, L4, L5 and L6.

Checks: Still running: 13 checks.

More: does it help, other systems, switches, what was read

Does it help: Yes, for the forced-full cases tested: four Windows starts each emptied 150 heaps and completed seven area changes without a crash, whereas the corresponding retry-disabled cases crashed. The reporter’s save and the merged head have not been run in the game, so recovery of that session remains unproven.

Other systems: The hooks affect material-block builds on several game threads and both Windows and Linux, regardless of GPU vendor. Only Windows on an RTX 5090 was exercised in game; parent-heap allocation lifetime, Linux, other Tier 1 systems and frame-time effects remain unverified.

Switches: HOS_GPU_ALLOC_REST is added on by default as a kill switch; the recovery case below prevents accepting that default as complete. HOS_GPU_ALLOC_TEST_FILL is added off by default for fault injection. HOS_GPU_ALLOC_TEST_FAIL gains an optional third count, with two-count behavior retaining zero for the new sites. All have switch-table rows.

Reviewed: 206dcde9a0 against 9046a8d750: Read AGENTS.md, CONTRIBUTING.md, the pull request template, relevant standards, commit messages, the changed host implementation and heap-patching sections, and the changed test and switch entries. Skimmed the remainder of nx2/oot_patches.py and the switch table; docs/review-checklist.md and ../Tooling/AGENTS.md were absent. No recorded runs or generated files were added.; nothing run (a code review).

Checked and fine:

  • The changed switches have switch-table entries, and test subprocesses remove inherited HOS_GPU_ALLOC switches.
  • The commits record AI assistance, and the change does not alter the renderer API or shader sources.
  • The reported Windows fault-injection runs cover hand-over from four allocation sites and include a no-switch run.

Testing: Read-only review; no builds, tests, or project scripts were run. The supplied CI checks were still running.

Overlaps and merge order: Not checked; the network is closed.


Automated code review by BeanBot (gpt-6.1-terra), asked for by llun. Nothing was run; a maintainer decides.

**Recommendation: Request changes.** The retry can still leave the rest of a build on a full heap even when a higher parent has room, and its new shared state has data races. The test also commits passages shaped from lifted game code, contrary to the repository’s game-data rule. The change retries five more material-block allocations and moves subsequent allocations to a parent heap. Forced-full Windows runs show the approach can avoid the reported crashes, but recovery is incomplete in one parent-heap case and its memory lifetime and cross-platform behavior need further validation. **Blocking (2)**: must change before merging. 1. **L1** `host/oot_heap_retry.c:342`: The retry stops at the first parent that can satisfy the individual allocation, even if that parent cannot support the rest of the build. (more on the line) **Do:** Select a parent suitable for the whole hand-over before allocating the retried block, continuing up the chain when the nearest parent is too small, and add a test with a small intermediate parent and a sufficiently large ancestor. 2. **L4** `tests/test_oot_heap_retry.py:476`: The new fixture includes passages presented as lifted game instructions, which the repository prohibits committing. (more on the line) **Do:** Replace the passages with independently authored synthetic fixtures containing only the minimal patch anchors and fabricated surrounding behavior, and remove the sampled game-derived sequences from the commits. **Should fix (2)**: not blocking, but worth doing before merging. - **L2** `host/oot_heap_retry.c:93`: The new cached switch value is read and written without synchronization across game threads. (more on the line) **Do:** Initialize and publish the cached value with atomics or a once primitive, or read the switch without a shared mutable cache. - **L3** `host/oot_heap_retry.c:295`: The test-fill counter is read outside its lock while other threads decrement it under the lock; volatile does not make those accesses atomic. (more on the line) **Do:** Use atomic accesses consistently for left, including its decrement, or perform every access under the same lock. **Testing before merging (2)** (runs on the systems it can change; it doesn't hold the recommendation) - **L5** `host/oot_heap_retry.c:348`: The new parent-heap hand-over needs a longer lifetime check and runs on the supported platforms it affects. (more on the line) **Do:** Run repeated model rebuilds and area changes on Linux and representative Tier 1 systems, tracking parent-heap use after the models are released; also test the reporter’s reproducible save if available. *(`@fix` does its part first: Add accounting for the allocations made after hand-over so a repeated-load run can distinguish retained build memory from unrelated parent-heap use.)* - **L6** `nx2/oot_patches.py:1496`: The hot functions now lose register-local optimization and execute additional hooks, but their frame-time cost has not been measured. (more on the line) **Do:** Compare the base and head with repeated interleaved runs in material-heavy gameplay, recording frame-time distribution and 1% lows. *(`@fix` does its part first: Restructure the hook insertion so these functions can retain register-local optimization, or avoid the per-allocation test hook in ordinary builds.)* `@fix` can do L1, L2, L3, L4, L5 and L6. **Checks:** Still running: 13 checks. <details> <summary>More: does it help, other systems, switches, what was read</summary> **Does it help:** Yes, for the forced-full cases tested: four Windows starts each emptied 150 heaps and completed seven area changes without a crash, whereas the corresponding retry-disabled cases crashed. The reporter’s save and the merged head have not been run in the game, so recovery of that session remains unproven. **Other systems:** The hooks affect material-block builds on several game threads and both Windows and Linux, regardless of GPU vendor. Only Windows on an RTX 5090 was exercised in game; parent-heap allocation lifetime, Linux, other Tier 1 systems and frame-time effects remain unverified. **Switches:** HOS_GPU_ALLOC_REST is added on by default as a kill switch; the recovery case below prevents accepting that default as complete. HOS_GPU_ALLOC_TEST_FILL is added off by default for fault injection. HOS_GPU_ALLOC_TEST_FAIL gains an optional third count, with two-count behavior retaining zero for the new sites. All have switch-table rows. **Reviewed:** 206dcde9a051 against 9046a8d75019: Read AGENTS.md, CONTRIBUTING.md, the pull request template, relevant standards, commit messages, the changed host implementation and heap-patching sections, and the changed test and switch entries. Skimmed the remainder of nx2/oot_patches.py and the switch table; docs/review-checklist.md and ../Tooling/AGENTS.md were absent. No recorded runs or generated files were added.; nothing run (a code review). **Checked and fine:** - The changed switches have switch-table entries, and test subprocesses remove inherited HOS_GPU_ALLOC switches. - The commits record AI assistance, and the change does not alter the renderer API or shader sources. - The reported Windows fault-injection runs cover hand-over from four allocation sites and include a no-switch run. **Testing:** Read-only review; no builds, tests, or project scripts were run. The supplied CI checks were still running. **Overlaps and merge order:** Not checked; the network is closed. </details> --- <sub>Automated code review by BeanBot (gpt-6.1-terra), asked for by llun. Nothing was run; a maintainer decides.</sub>
@ -50,1 +91,3 @@
/* HOS_GPU_ALLOC_TEST_FAIL: 1 while this kind's first n allocations are refused (kind 0 the GPU memory, 1 the CPU buffer) */
static int rest_on(void) {
static int on = -1;
if (on < 0) on = env_on_or("HOS_GPU_ALLOC_REST", 1);
Member

L2 (should fix): The new cached switch value is read and written without synchronization across game threads.

When: When two threads first recover full heaps concurrently, both can read and write the static on value in rest_on. These conflicting plain accesses form a C data race, making the recovery path undefined even when both read the same environment value.

Do: Initialize and publish the cached value with atomics or a once primitive, or read the switch without a shared mutable cache.

**L2** (should fix): The new cached switch value is read and written without synchronization across game threads. *When:* When two threads first recover full heaps concurrently, both can read and write the static on value in rest_on. These conflicting plain accesses form a C data race, making the recovery path undefined even when both read the same environment value. **Do:** Initialize and publish the cached value with atomics or a once primitive, or read the switch without a shared mutable cache.
@ -208,0 +292,4 @@
}
__sync_lock_release(&lock);
}
if (left <= 0 || lr != at || !holder || !readable(heap) || rest.holder == holder) return;
Member

L3 (should fix): The test-fill counter is read outside its lock while other threads decrement it under the lock; volatile does not make those accesses atomic.

When: With HOS_GPU_ALLOC_TEST_FILL enabled, two model-building threads can reach this check while one decrements left at line 303. The resulting data race makes the fault-injection run undefined and can invalidate the multi-threaded test result.

Do: Use atomic accesses consistently for left, including its decrement, or perform every access under the same lock.

**L3** (should fix): The test-fill counter is read outside its lock while other threads decrement it under the lock; volatile does not make those accesses atomic. *When:* With HOS_GPU_ALLOC_TEST_FILL enabled, two model-building threads can reach this check while one decrements left at line 303. The resulting data race makes the fault-injection run undefined and can invalidate the multi-threaded test result. **Do:** Use atomic accesses consistently for left, including its decrement, or perform every access under the same lock.
@ -208,0 +339,4 @@
if (got && site >= 0) count_moved(1 + site, size, say);
if (got && rest_on() && holder && readable(heap) && recomp_load64(c, holder + 8) == heap) {
const uint64_t f = free_size(c, in), whole = recomp_load64(c, heap + HEAP_SIZE);
if (f != ~0ULL && f < whole + 0x2000) {
Member

L1 (blocking): The retry stops at the first parent that can satisfy the individual allocation, even if that parent cannot support the rest of the build.

When: If the model heap is full, its immediate parent can fit the 0x238-byte object plus the retry margin but has less than the model heap’s size free, and a higher parent has ample room, the object is allocated in the immediate parent. This check leaves the holder pointing at the full model heap; an unchecked later allocation such as f_8044e020’s object can then return null and crash, despite the higher parent having room.

Do: Select a parent suitable for the whole hand-over before allocating the retried block, continuing up the chain when the nearest parent is too small, and add a test with a small intermediate parent and a sufficiently large ancestor.

**L1** (blocking): The retry stops at the first parent that can satisfy the individual allocation, even if that parent cannot support the rest of the build. *When:* If the model heap is full, its immediate parent can fit the 0x238-byte object plus the retry margin but has less than the model heap’s size free, and a higher parent has ample room, the object is allocated in the immediate parent. This check leaves the holder pointing at the full model heap; an unchecked later allocation such as f_8044e020’s object can then return null and crash, despite the higher parent having room. **Do:** Select a parent suitable for the whole hand-over before allocating the retried block, continuing up the chain when the nearest parent is too small, and add a test with a small intermediate parent and a sufficiently large ancestor.
@ -208,0 +345,4 @@
} else {
/* (a parent that ran out in its turn hands the build on: the build's own heap stays the one to put back) */
if (rest.holder != holder || rest.in != heap) rest.own = heap, rest.gpu = 0;
recomp_store64(c, holder + 8, in);
Member

L5 (should fix): The new parent-heap hand-over needs a longer lifetime check and runs on the supported platforms it affects.

When: After a full model heap triggers the hand-over, later allocations also come from the parent. The author traced several frees but not every allocation moved by the hand-over; a long session and Linux have not been tested.

Do: Run repeated model rebuilds and area changes on Linux and representative Tier 1 systems, tracking parent-heap use after the models are released; also test the reporter’s reproducible save if available.

**L5** (should fix): The new parent-heap hand-over needs a longer lifetime check and runs on the supported platforms it affects. *When:* After a full model heap triggers the hand-over, later allocations also come from the parent. The author traced several frees but not every allocation moved by the hand-over; a long session and Linux have not been tested. **Do:** Run repeated model rebuilds and area changes on Linux and representative Tier 1 systems, tracking parent-heap use after the models are released; also test the reporter’s reproducible save if available.
@ -1483,0 +1493,4 @@
# f_8044f420's 0x238-byte object for each entry of its list (0x8044f66c; the holder is x21), cleared at once (issue 2437:
# write guest 0x20, thread OptimizeChangeBanc, lr 0x8044f684); the two buffers f_8044ed60 takes for that object (the
# holder is x22 there); f_80443000's buffer and its 0x310-byte object (the holder is its fourth argument, kept at sp+0)
OBJECT_ALLOC_SITES = ((0x8044f670, "c->x[21]"), (0x8044efc8, "c->x[22]"), (0x8044f074, "c->x[22]"),
Member

L6 (should fix): The hot functions now lose register-local optimization and execute additional hooks, but their frame-time cost has not been measured.

When: The added addresses keep f_8044f420 and f_80443000 in the context-based form on every call, including normal play when no allocation fails. The reported area-change timings are uncontrolled and do not measure frame pacing.

Do: Compare the base and head with repeated interleaved runs in material-heavy gameplay, recording frame-time distribution and 1% lows.

**L6** (should fix): The hot functions now lose register-local optimization and execute additional hooks, but their frame-time cost has not been measured. *When:* The added addresses keep f_8044f420 and f_80443000 in the context-based form on every call, including normal play when no allocation fails. The reported area-change timings are uncontrolled and do not measure frame pacing. **Do:** Compare the base and head with repeated interleaved runs in material-heavy gameplay, recording frame-time distribution and 1% lows.
@ -237,0 +473,4 @@
# (f_8044f420's place, as the lift writes it for a function the edits keep in the context: the heap's tryAlloc of the
# 0x238-byte object and the clear that follows it; and the places of f_8044ed60 and f_80443000 after it, in files of
# their own in a lift (the hot list's)
OBJECT_FUNCTION = '''void f_8044f420(Ctx *__restrict A64_NOESC c) {
Member

L4 (blocking): The new fixture includes passages presented as lifted game instructions, which the repository prohibits committing.

When: OBJECT_FUNCTION and the new sequences in OTHER_FUNCTIONS and LIFTED reproduce the lifted calls and surrounding register operations from the game. CONTRIBUTING.md excludes lifted C and anything generated from the dump, including samples used in tests.

Do: Replace the passages with independently authored synthetic fixtures containing only the minimal patch anchors and fabricated surrounding behavior, and remove the sampled game-derived sequences from the commits.

**L4** (blocking): The new fixture includes passages presented as lifted game instructions, which the repository prohibits committing. *When:* OBJECT_FUNCTION and the new sequences in OTHER_FUNCTIONS and LIFTED reproduce the lifted calls and surrounding register operations from the game. CONTRIBUTING.md excludes lifted C and anything generated from the dump, including samples used in tests. **Do:** Replace the passages with independently authored synthetic fixtures containing only the minimal patch anchors and fabricated surrounding behavior, and remove the sampled game-derived sequences from the commits.
Member
@fix
Owner
@fix
fix(heap): choose a parent for the full material build
Some checks failed
Website / Website on Cloudflare (pull_request_target) Has been skipped
Website / Website builds (pull_request_target) Has been skipped
Website / Website preview, build (pull_request_target) Has been skipped
Website / Website preview, upload (pull_request_target) Has been skipped
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been skipped
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been skipped
Third-party parts / The same as upstream (pull_request) Has been skipped
Website / Website on Cloudflare (pull_request) Has been skipped
Website / Website preview, build (pull_request) Has been skipped
Website / Website preview, upload (pull_request) Has been skipped
PR description / Description follows the template (pull_request_target) Has been cancelled
CI / Conventional Commit title (pull_request) Successful in 8s
CI / Workflow lint (actionlint) (pull_request) Successful in 16s
Guide screenshots / Guide images and local UI source review (pull_request) Successful in 17s
Third-party parts / As their notes say (pull_request) Successful in 18s
CI / Website build and checks (pull_request) Successful in 2m0s
Website / Website builds (pull_request) Successful in 2m1s
3bb0b989be
As the review on #2452 asked.
BeanBot left a comment

Recommendation: Request changes. The current fixture is synthetic, but the pull request’s earlier commits still contain passages presented as lifted game instructions, contrary to the repository’s licensing rule. The hand-over’s lifetime and frame-time costs also remain unmeasured.

What @fix changed
I changed this pull request: the new head is 3bb0b989be. I merged main (3395639aad) into it, as it has merge commits. I edited its description to match the change.

Changed

  • Parent selection in host/oot_heap_retry.c:257: Selects a parent with room for the allocation and the rest of the build before allocating. Added cases for a small intermediate parent and for no suitable parent in tests/test_oot_heap_retry.py:373.
  • Switch cache in host/oot_heap_retry.c:91: Reads the switch without a shared mutable cache; the retry switch uses the same approach.
  • Test-fill counter in host/oot_heap_retry.c:292: Made every counter read and decrement atomic while retaining the lock for the filled-heap list. Tests were not run, as requested.

Changed in part (the rest is for the author)

  • Allocation hooks in nx2/oot_patches.py:1487: Skipped the per-allocation fault-injection call when its test switches are off, initialized before game threads start in host/hos_main.c:2175. The author still needs to measure frame time on the affected platforms.

Not done

  • Hand-over lifetime accounting in host/oot_heap_retry.c:56: Accounting for subsequent allocations and their frees remains needed to distinguish retained build memory from unrelated parent-heap use. The existing counters and free-size logs cannot make that distinction.

Left for the author

  • Remove game-derived fixture passages from branch history: The current fixture is synthetic at tests/test_oot_heap_retry.py:483. The author must rewrite the pull request’s earlier commits to remove the sampled passages while preserving the fix; this checkout’s rules prohibit changing Git history.

Nothing was built or run: the checks run again on the new head.

The change retries several material-block allocations in parent heaps and moves the rest of a build there after a retry, aiming to prevent crashes when a model heap fills. It adds allocation hooks and can move build memory into a shared parent heap; their lifetime and performance costs remain uncertain.

Blocking (1): must change before merging.

  1. L4 tests/test_oot_heap_retry.py:476: The new fixture includes passages presented as lifted game instructions, which the repository prohibits committing. When: OBJECT_FUNCTION and the new sequences in OTHER_FUNCTIONS and LIFTED reproduce the lifted calls and surrounding register operations from the game. CONTRIBUTING.md excludes lifted C and anything generated from the dump, including samples used in tests. Do: Replace the passages with independently authored synthetic fixtures containing only the minimal patch anchors and fabricated surrounding behavior, and remove the sampled game-derived sequences from the commits. (for the author: @fix couldn't: The fixture at tests/test_oot_heap_retry.py:483 is synthetic, but the earlier branch commits still contain the passages presented as lifted instructions. The author must remove those passages from bra)

Testing before merging (2) (runs on the systems it can change; it doesn't hold the recommendation)

  • L5 host/oot_heap_retry.c:348: The new parent-heap hand-over needs a longer lifetime check and runs on the supported platforms it affects. When: After a full model heap triggers the hand-over, later allocations also come from the parent. The author traced several frees but not every allocation moved by the hand-over; a long session and Linux have not been tested. Do: Run repeated model rebuilds and area changes on Linux and representative Tier 1 systems, tracking parent-heap use after the models are released; also test the reporter’s reproducible save if available.
  • L6 nx2/oot_patches.py:1496: The hot functions now lose register-local optimization and execute additional hooks, but their frame-time cost has not been measured. When: The added addresses keep f_8044f420 and f_80443000 in the context-based form on every call, including normal play when no allocation fails. The reported area-change timings are uncontrolled and do not measure frame pacing. Do: Compare the base and head with repeated interleaved runs in material-heavy gameplay, recording frame-time distribution and 1% lows.

Checks: they run again on this head; a failure shows on the pull request.

Also noticed (2; not asked for, not blocking)
  • The current head’s CI checks have not run.
  • The recorded game runs predate the parent-selection and test-hook changes.
More: does it help, other systems, switches, what was read

Does it help: Unproven on the current head. On the earlier tested build, Windows runs continued through seven area changes with 150 heaps forcibly filled at each of four sites; the corresponding unfixed allocation cases crashed. The reporter’s save and the current fix have not been run in game.

Other systems: The hand-over affects CPU and sometimes GPU allocations on several game threads. Linux behavior, longer-lived parent-heap allocations, and frame-time effects remain untested; the recorded game runs used Windows and NVIDIA hardware.

Switches: HOS_GPU_ALLOC_REST is added, on by default; HOS_GPU_ALLOC_TEST_FILL is added, off by default; HOS_GPU_ALLOC_TEST_FAIL gains a third count and remains off by default. The test switches are appropriate as opt-in diagnostics; the hand-over default still needs the lifetime and platform evidence in L5.

Reviewed: 3bb0b989be against 3395639aad: Read AGENTS.md, CONTRIBUTING.md, the pull request template, host/oot_heap_retry.c, the fix diff and the prior fixture passages. Inspected the heap patch and test changes and the switch references. The full base diff includes merged title-card changes; those files, the complete large patch and test files, and other dependent code were not read in full.; nothing run (a code review).

Checked and fine:

  • The current fixture replaces the identified instruction passages with synthetic surrounding statements.
  • The fix retains the parent-heap retry and hand-over paths.

Testing: No commands that build, run tests, or execute project code were run. The author reports game and game-free checks on earlier trees; the current head still needs CI and the runs described in the ledger.

Overlaps and merge order: Not checked; network access is closed.


Automated code review by BeanBot (gpt-6.1-terra), asked for by BeanBot, after its fix. Nothing was run; a maintainer decides.

**Recommendation: Request changes.** The current fixture is synthetic, but the pull request’s earlier commits still contain passages presented as lifted game instructions, contrary to the repository’s licensing rule. The hand-over’s lifetime and frame-time costs also remain unmeasured. **What `@fix` changed** I changed this pull request: the new head is 3bb0b989be0a. I merged `main` (3395639aad05) into it, as it has merge commits. I edited its description to match the change. **Changed** - **Parent selection in host/oot_heap_retry.c:257**: Selects a parent with room for the allocation and the rest of the build before allocating. Added cases for a small intermediate parent and for no suitable parent in tests/test_oot_heap_retry.py:373. - **Switch cache in host/oot_heap_retry.c:91**: Reads the switch without a shared mutable cache; the retry switch uses the same approach. - **Test-fill counter in host/oot_heap_retry.c:292**: Made every counter read and decrement atomic while retaining the lock for the filled-heap list. Tests were not run, as requested. **Changed in part (the rest is for the author)** - **Allocation hooks in nx2/oot_patches.py:1487**: Skipped the per-allocation fault-injection call when its test switches are off, initialized before game threads start in host/hos_main.c:2175. The author still needs to measure frame time on the affected platforms. **Not done** - **Hand-over lifetime accounting in host/oot_heap_retry.c:56**: Accounting for subsequent allocations and their frees remains needed to distinguish retained build memory from unrelated parent-heap use. The existing counters and free-size logs cannot make that distinction. **Left for the author** - **Remove game-derived fixture passages from branch history**: The current fixture is synthetic at tests/test_oot_heap_retry.py:483. The author must rewrite the pull request’s earlier commits to remove the sampled passages while preserving the fix; this checkout’s rules prohibit changing Git history. Nothing was built or run: the checks run again on the new head. The change retries several material-block allocations in parent heaps and moves the rest of a build there after a retry, aiming to prevent crashes when a model heap fills. It adds allocation hooks and can move build memory into a shared parent heap; their lifetime and performance costs remain uncertain. **Blocking (1)**: must change before merging. 1. **L4** `tests/test_oot_heap_retry.py:476`: The new fixture includes passages presented as lifted game instructions, which the repository prohibits committing. *When:* OBJECT_FUNCTION and the new sequences in OTHER_FUNCTIONS and LIFTED reproduce the lifted calls and surrounding register operations from the game. CONTRIBUTING.md excludes lifted C and anything generated from the dump, including samples used in tests. **Do:** Replace the passages with independently authored synthetic fixtures containing only the minimal patch anchors and fabricated surrounding behavior, and remove the sampled game-derived sequences from the commits. *(for the author: `@fix` couldn't: The fixture at tests/test_oot_heap_retry.py:483 is synthetic, but the earlier branch commits still contain the passages presented as lifted instructions. The author must remove those passages from bra)* **Testing before merging (2)** (runs on the systems it can change; it doesn't hold the recommendation) - **L5** `host/oot_heap_retry.c:348`: The new parent-heap hand-over needs a longer lifetime check and runs on the supported platforms it affects. *When:* After a full model heap triggers the hand-over, later allocations also come from the parent. The author traced several frees but not every allocation moved by the hand-over; a long session and Linux have not been tested. **Do:** Run repeated model rebuilds and area changes on Linux and representative Tier 1 systems, tracking parent-heap use after the models are released; also test the reporter’s reproducible save if available. - **L6** `nx2/oot_patches.py:1496`: The hot functions now lose register-local optimization and execute additional hooks, but their frame-time cost has not been measured. *When:* The added addresses keep f_8044f420 and f_80443000 in the context-based form on every call, including normal play when no allocation fails. The reported area-change timings are uncontrolled and do not measure frame pacing. **Do:** Compare the base and head with repeated interleaved runs in material-heavy gameplay, recording frame-time distribution and 1% lows. **Checks:** they run again on this head; a failure shows on the pull request. <details> <summary>Also noticed (2; not asked for, not blocking)</summary> - The current head’s CI checks have not run. - The recorded game runs predate the parent-selection and test-hook changes. </details> <details> <summary>More: does it help, other systems, switches, what was read</summary> **Does it help:** Unproven on the current head. On the earlier tested build, Windows runs continued through seven area changes with 150 heaps forcibly filled at each of four sites; the corresponding unfixed allocation cases crashed. The reporter’s save and the current fix have not been run in game. **Other systems:** The hand-over affects CPU and sometimes GPU allocations on several game threads. Linux behavior, longer-lived parent-heap allocations, and frame-time effects remain untested; the recorded game runs used Windows and NVIDIA hardware. **Switches:** HOS_GPU_ALLOC_REST is added, on by default; HOS_GPU_ALLOC_TEST_FILL is added, off by default; HOS_GPU_ALLOC_TEST_FAIL gains a third count and remains off by default. The test switches are appropriate as opt-in diagnostics; the hand-over default still needs the lifetime and platform evidence in L5. **Reviewed:** 3bb0b989be0a against 3395639aad05: Read AGENTS.md, CONTRIBUTING.md, the pull request template, host/oot_heap_retry.c, the fix diff and the prior fixture passages. Inspected the heap patch and test changes and the switch references. The full base diff includes merged title-card changes; those files, the complete large patch and test files, and other dependent code were not read in full.; nothing run (a code review). **Checked and fine:** - The current fixture replaces the identified instruction passages with synthetic surrounding statements. - The fix retains the parent-heap retry and hand-over paths. **Testing:** No commands that build, run tests, or execute project code were run. The author reports game and game-free checks on earlier trees; the current head still needs CI and the runs described in the ledger. **Overlaps and merge order:** Not checked; network access is closed. </details> --- <sub>Automated code review by BeanBot (gpt-6.1-terra), asked for by BeanBot, after its fix. Nothing was run; a maintainer decides.</sub>
HumanBean deleted branch fix/matblock-alloc-retry 2026-11-25 05:03:36 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
4 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
MagicBeanDev/Longshot!2452
No description provided.