fix(oot): a full model heap hands the rest of its material block to the parent heap instead of crashing #2452
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/renderer
area/saves
area/tooling
area/upscaling
beanstalk: approved
beanstalk: failed
beanstalk: needs approval
beanstalk: running
beanstalk: tested
ci: approved
good first issue
gpu/amd
gpu/igpu
gpu/intel
gpu/nvidia
help wanted
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
needs measurements
platform/linux
platform/macos
platform/steam-deck
platform/windows
preview
priority
critical
priority
high
priority
low
regression
risk
high
risk
low
risk
medium
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
ci: approved
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!2452
Loading…
Reference in a new issue
No description provided.
Delete branch "PirateKingIsh/Longshot:fix/matblock-alloc-retry"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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.calready tries the block's two buffers and its GPU memory again in the heap's parents. Two things were left:Three changes:
HOS_GPU_ALLOC_REST=0turns this part off.HOS_GPU_ALLOC_TEST_FILL=<n>[,<place>]empties the first n model heaps that reach a place (the call's address; left out, the object's), through their own tryAlloc. To see the bug with this branch's build:HOS_GPU_ALLOC_TEST_FILL=1 HOS_GPU_ALLOC_RETRY=0crashes while the game starts on #2437's line, andHOS_GPU_ALLOC_TEST_FILL=1,0x80443e2c HOS_GPU_ALLOC_RETRY=0on 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"), itsSITEStable,hos_oot_heap_retry,hos_oot_heap_rest_ownandhos_oot_heap_rest_end; thenOBJECT_ALLOC_SITES,REST_OWN_SITESandREST_END_SITESinnx2/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
eebb1e6dwith the second commit's changes, built before that commit (the log'slongshot v3.2.0-13-geebb1e6d-dirty). The four files committed are the ones that were built; their hashes were checked before the commit.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:write ..., guest 0x20, lr 0x8044f684, x0 0x10, x2 0x228, x20 0, with the first eight guest frames of #2437's report (there on OptimizeChangeBanc).write ..., guest 0, lr 0x80443e30 0x8044dcb8 0x8044cf14 0x80456d48. The crash bot's groups3c3421252152,c384a6da8184,9122fc95b8c9,d69d4996d756,395dbd5efd30(10 reports) have these frames.write ..., guest 0x190, lr 0x80443240 0x8044dcb8 0x8044cf14 0x80456d48. Groups7f6d6dd2100d,93a7083f0baf,9e83ad4976d1(4 reports).write ..., guest 0, lr 0x8044f3c0 0x8044f088 0x8044f6f4 0x8044dbd0. Groupsaa6ab20813b9,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):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: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
ageandteleport): Gerudo Valley, Gerudo's Fortress, Gerudo Valley, Kokiri Forest, Hyrule Field, Kakariko, Gerudo Valley. NoCRASH: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.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.pyfails on main's sources (f_8044f420's tryAlloc of its 0x238-byte object (0x8044f66c) is not tried again: issue 2437's crash) and passes on this branch (14 PASS lines). The whole Windows run of the checks (tests/run_all.py): 823 passed, 27 failed, 129 skipped. These 27 fail on main8aa5ab87too, run there on the same PC:tests/test_amd_subgroup_profiles.py,tests/test_auto_handheld.py,tests/test_crash_dialog.py,tests/test_crt_options.py,tests/test_dev_ab.py,tests/test_dev_build.py,tests/test_dev_migrate.py,tests/test_dev_packs.py,tests/test_flat_map.py,tests/test_game_menu_mouse_buttons.py,tests/test_input_movie.py,tests/test_linux_preflight.py,tests/test_menu_text_field.py,tests/test_pads_after_menu.py,tests/test_perf_report.py,tests/test_pipeline_share.py,tests/test_portable_builder_home.py,tests/test_portable_builder_startup.py,tests/test_rdna2_mesh_only.py,tests/test_readback_timeout_source.py,tests/test_rumble_menu.py,tests/test_sdiv_overflow.py,tests/test_shader_profile_caps.py,tests/test_target_image_reuse.py,tests/test_vibration_menu.py,tests/test_vram_compact.py,tests/test_work_lock.py.Still to test:
HOS_GPU_ALLOC_TEST_FILL=150,0x8045690c, load a save and change area a few times, expecting no crash andoot: model buffer: the rest of the build takes its memory fromlines in the log (Test Farm if a maintainer wants it, or by hand).oot:line withthe rest of the build takes its memoryinlongshot_log.txtshows it ran (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 it plays on.
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 this commit'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.HOS_GPU_ALLOC_RETRY=0(the allocations as main has them): this PR @ef42c238HOS_GPU_ALLOC_REST=0(each allocation alone): this PR @ef42c238ef42c238tests/test_oot_heap_retry.pyBefore, the object (asset names shortened):
Before, f_80443000's object:
Each allocation alone (the last one made in the parent, then the crash):
After, f_80443000's object (the first of the 150, and the last count line):
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
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.HOS_GPU_ALLOC_REST=0(the hand-over alone) orHOS_GPU_ALLOC_RETRY=0(every retry, as shipped).nx2/oot_patches.pynow 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).longshot_options.inior the caches.Checklist
Ready for review
main; the title is a Conventional Commit.mise run testpasses (any failure that also fails onmainis named).main, or Measurements says why there is nothing to measure.third_party/untouched; nothing GPL-incompatible.When it applies
mainand passes here.gpu/vk/switches.def.HOS_GPU_ALLOC_RESTis on by default (off is start 5 above);HOS_GPU_ALLOC_TEST_FILLis a test switch, off by default;HOS_GPU_ALLOC_TEST_FAIL(a test) takes a third number.tests/that reads changed source is updated, not weakened._Thread_localashost/hos_main.cdoes).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
main, measured again or a comment says why the numbers still hold.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=0the game crashes while it starts on the report's line (write ..., guest 0x20, lr 0x8044f684). WithHOS_GPU_ALLOC_TEST_FILL=150and 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 nooot:line. The game-free check fails on main's sources and passes on this branch.fix(oot): a full model heap hands the rest of its material block to the parent heap instead of crashingto WIP(oot): a full model heap hands the rest of its material block to the parent heap instead of crashingWIP(oot): a full model heap hands the rest of its material block to the parent heap instead of crashingto WIP: a full model heap hands the rest of its material block to the parent heap instead of crashingWIP: a full model heap hands the rest of its material block to the parent heap instead of crashingto fix(oot): a full model heap hands the rest of its material block to the parent heap instead of crashingI 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.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.