Repository navigation
Description
What
With MSVC's /Zc:lambda, a lambda whose capture copy throws terminates the process (std::terminate) instead of unwinding to the caller's handler. /Zc:lambda is on whenever /permissive- is, and the CMake targets of the front end build with /permissive-, so every release build of the in-game code has it on. A capture copy can throw whenever the captured object allocates when it is copied (std::string, std::vector, std::function holding a large callable): the throw is std::bad_alloc, so the case is out of memory, and the process ends in std::terminate instead of the error path.
It was found in the create worker's device hold (#225): [release, device] { release(device); } captured a std::function by copy. A test with a callable whose copy throws aborted with exit code 0xc0000409 in the CI configuration (cmake, Release, /permissive- /W4 /Zi) and not in a hand-made cl build without /permissive-. A stand-alone reproduction narrowed it to this switch: with /Zc:lambda alone the throw terminates, without it the exception reaches the catch; a plain copy of the same std::function (no lambda) is fine in every configuration.
Rule (proposed)
No lambda in code that runs in a game may capture, by copy or by init-capture, an object whose copy can throw. Use one of:
- a named callable class whose constructor does the copy (that unwinds normally; R1: no in-game route to HIP; GPU identity from the driver; other cards use the front end's upscaler #225 does this:
DeviceReleaseinclean/fsr/src/async_create.h), or - a capture whose copy cannot throw: a raw pointer, an index, a
std::shared_ptr(copy isnoexcept), or astd::moveinto an init-capture of a type with anoexceptmove.
Known site
clean/fsr/src/dllmain.cpp: p.modelPlaces = [modelDir = config.modelDir] { ... } init-captures a std::string by copy at start-up. Out of memory at that point ends in std::terminate instead of the normal failure. It is the same class; it is not part of #225.
Asked for (0.6.6)
- Audit the whole in-game tree (front end, the D3D12 runtime and its interop, the Ray Reconstruction plugin and runtime, shared code that runs in the game process) for lambdas with a by-copy or init-capture of a type whose copy can throw; fix each as above.
- Write the rule in the contributor notes next to the other code rules.
- Optional: a small CI check (a grep for init-captures of
std::string/std::vector/std::functionin the in-game sources) so the rule holds. - Keep a test that drives a throwing copy through any callable the fix touches (see
TestDeviceHoldAllocationFailureinclean/fsr/tests/test_frontend.cpp): it must pass in the CI configuration.
Activity
phantoslayer21 commentedon Nov 15, 2026
Audit of the code that runs in a game, at #213's head (front end, menu plugin, shared headers, RR plugin, runtime): lambdas that capture by copy an object whose copy can throw.
Fixed in #213 (named classes now):
clean/fsr/src/dllmain.cpp(wronggpu.ini's reader, the model places, AMD's DLL) andclean/fsr/src/win_util.h(the comparison DLL).Still open, outside #213's code:
clean/rr_f/proxy/src/hook_dll.cpp:1765:[setting, exe], twostd::strings, passed towgsi::install.clean/rr_f/runtime/src/rr_runtime.cpp:1437:[dev, rs, blobs, start_vbits],blobsis astd::vector<const RrKernelBlob*>, passed to the compile thread.clean/runtime/interop/executor_d3d12.cpp:154:[sink = log_], astd::function, passed toset_log_sink.clean/runtime/interop/executor_hip.cpp:51: the same[sink = log_].The other copy captures found are pointers, a
bool, ashared_ptr(non-throwing copy) or astd::string*, which are fine.