fix(vk): a C++ exception out of the renderer is said and stops the game as out of memory or a FATAL line, not 0x20474343 #2170
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
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!2170
Loading…
Reference in a new issue
No description provided.
Delete branch "HumanBean/Longshot:fix/renderer-cxx-escape"
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
When a C++ exception gets out of the renderer (
longshot_vk.dll), nothing catches it. The host is C, and a renderer thread's body is the top of its stack. So the game ends with exception0x20474343(llvm-mingw's code for a C++ exception nothing caught) and "An unexpected error". The log doesn't say what was thrown or where.#1291 gave the renderer a
new_handler, so a refusedoperator newwaits and then says out of memory. But the crash bot on #81 still lists0x20474343on v3.0.0, which has #1291:KERNELBASE.dll+0xc569a: 12 reports;+0xc408a: 4 reports;+0x25369: 3 reports.Several of these logs reach the commit limit with no
vk: a C++ allocation refusedline before the crash, so what was thrown there wasn't a refusedoperator new. It's also one of the two crash kinds in #947 (AMD APUs and handhelds, loading a save). #1280 itself is closed, with its duplicates.The likely candidates, from reading the code:
std::thread's constructor throwsstd::system_error. The texture decode starts helper threads during play, from astd::vector<std::thread>: a failed start there destroys the vector while the other threads are still running, which isstd::terminate.std::length_errororstd::bad_array_new_lengthfrom a vector)..at()(std::out_of_range).std::filesystemcall without anerror_code.This PR catches them at the ways out and stops the game with what was thrown (
gpu/vk/cxx_escape.h):MkwVkRenderer, wrapped bygpu/vk/renderer_guard.hwhenmkwvk_initreturns the table), andmkwvk_inititself.spawn_needed. Their bodies catch, and a thread that can't be started stops the game as out of memory. A thread that fails to start inside one of these, or inside a host call, comes out as astd::system_errorinto the same catch.fork_join. A helper that can't be started leaves its part to the thread that asked, so the game no longer hitsstd::terminate.What's caught goes into the log as
vk: a C++ exception came out of <where>: <type>: <what()>. Then:std::bad_alloc, or astd::system_errorfor no memory or a thread that couldn't be started: the host's out-of-memory line and notice, as #1291 does.vk: FATAL:line (exit 3), which the crash window shows.Only
std::exceptionis caught, nevercatch (...). An access violation, or a driver's MSVC exception (0xe06d7363:nvgpucomp64.dll,AudioDevProps2.dllin #81), stays the crash record's, with its backtrace.The game still stops: a half-done replay isn't safe to go on from. What changes is that the player sees "out of memory" when that's the cause, and the log names everything else.
On
main: an exception out of anyMkwVkRendererfunction crashes with0x20474343and no line saying what it was.tests/test_cxx_escape.pyshows each kind.Read first:
gpu/vk/cxx_escape.h,gpu/vk/renderer_guard.h,mkwvk_init/init_bodyingpu/vk/vk_main.cpp.See #1280 (closed, still seen on v3.0.0). See #947.
Testing
Tested: Linux, RTX 3090, NVIDIA 620.70.06, this PR @
1a3655a9as a pack over main's base, through the job queue:kokiri-startthrough Kokiri Forest, Hyrule Field and the Market: in play, clean quit, nocame out oforcould not be startedline, no crash.HOS_TEST_ALLOC_REFUSE=renderer(#1291's hook):HOS_TEST_ALLOC_REFUSE: one C++ allocation of 1 PB, thena C++ allocation refused ... tried again for up to 5 s,the renderer's C++ allocations: still refused after 5 s, the out-of-memory line andFATAL: out of memory (RAM plus swap): the renderer's C++ allocations: the game stopped itself with the notice, as on main, with the table wrapped and the replay thread started throughspawn_needed; no 0x20474343.The game-free test (
tests/test_cxx_escape.pywithtests/cxx_escape_test.cpp) was not run on this PC (no test suites here); CI runs it. Only a compile check of the test file was made (g++andclang++ -fsyntax-only -Wall -Wextra -Werror, both clean). Onmainthe test fails becausegpu/vk/cxx_escape.his missing and nothing guards the table: the reason for the bug.Still to test:
nvn_presentor on the render thread is caught by the guard, not passed on as0x20474343. There's no switch that throws on demand, so the check is that a normal run plays as onmain, with novk: a C++ exception came out ofline (@Beanstalk a normal 10-minute run on Windows NVIDIA and AMD, and a Steam Deck, comparing withmain).Measurements
Nothing to measure for speed. Each
MkwVkRenderercall goes through one more function call with a table-basedtry, which costs nothing unless something throws. A normal run's fps againstmainis in the run plan, to confirm.Risks
std::bad_allocgoes through the host'shos_alloc_gave_up, whose line says "still refused after 5 s". With more than 1 GB of commit left, it's that function's "refused for 5 s with N MB of commit left" fatal instead.mkwvk_close_asked, whichtests/test_quit_not_crash.pyreads statement by statement.longshot_options.inior the caches.Checklist
Ready for review
main; the title is a Conventional Commit. (Rebased ontomain:499fcda2test,1a3655a9fix.)mise run testpasses (any failure that also fails onmainis named). (Not run on this PC: CI runs it. The tests that cut changed code were updated by reading them.)main, or Measurements says why there is nothing to measure.third_party/untouched; nothing GPL-incompatible.When it applies
mainand passes here. (It fails onmainby its source check; whether it passes here is for CI.)tests/that reads changed source is updated, not weakened. These follow the new text:test_renderer_new_handlerandtest_mesh_mode_switchreadinit_body;test_present_acquire_aheadreads the presenter'sspawn_neededline;test_texture_staging_publicationreads thefork_join. Thetest_guest_holesandtest_reserved_corefixtures includecxx_escape.h.docs/dev/reference/threads.md, "A C++ exception out of a thread").Assisted-by:/Co-Authored-By:trailers.Ready to merge
main, measured again or a comment says why the numbers still hold.🤖 Generated with Claude Code
Tested in game: Linux, RTX 3090, NVIDIA 620.70.06, through the job queue: memory tour Kokiri/Hyrule Field/Market, in play, clean quit, no new lines; with HOS_TEST_ALLOC_REFUSE=renderer the out-of-memory path ran as on main and stopped with the notice, no 0x20474343. Windows SEH behaviour needs the Test Farm.
@Beanstalk Windows NVIDIA, Windows AMD and a Steam Deck: a normal start from kokiri-start, play a few minutes through two or three areas, then quit. Expect it to play and close as on main, with no 'vk: a C++ exception came out of' line and no crash (this checks the new guards on Windows, where llvm-mingw's SEH unwinding is used).
Beanstalk test farm · planning the tests
Commit
1a3655a· approved by HumanBean (untrusted) · dashboardPlanning the tests for
1a3655a…WIP: fix(vk): a C++ exception out of the renderer is said and stops the game as out of memory or a FATAL line, not 0x20474343to fix(vk): a C++ exception out of the renderer is said and stops the game as out of memory or a FATAL line, not 0x20474343