Skip to content

0.6.6: lambdas that capture a throwing copy terminate under /Zc:lambda; audit the in-game tree #247

Open

Description

@phantoslayer21

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:

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)

  1. 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.
  2. Write the rule in the contributor notes next to the other code rules.
  3. Optional: a small CI check (a grep for init-captures of std::string / std::vector / std::function in the in-game sources) so the rule holds.
  4. Keep a test that drives a throwing copy through any callable the fix touches (see TestDeviceHoldAllocationFailure in clean/fsr/tests/test_frontend.cpp): it must pass in the CI configuration.

Activity

  1. phantoslayer21 commented on Nov 15, 2026

    @phantoslayer21
    OwnerAuthor

    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) and clean/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], two std::strings, passed to wgsi::install.
    • clean/rr_f/runtime/src/rr_runtime.cpp:1437: [dev, rs, blobs, start_vbits], blobs is a std::vector<const RrKernelBlob*>, passed to the compile thread.
    • clean/runtime/interop/executor_d3d12.cpp:154: [sink = log_], a std::function, passed to set_log_sink.
    • clean/runtime/interop/executor_hip.cpp:51: the same [sink = log_].

    The other copy captures found are pointers, a bool, a shared_ptr (non-throwing copy) or a std::string*, which are fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions