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

未关闭
#247 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
46/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
cmake, cpp

调研方向

Start with clean/fsr/src/dllmain.cpp and compare its modelPlaces capture with DeviceRelease in clean/fsr/src/async_create.h; then audit the in-game tree listed in the issue for other throwing lambda captures. Read the contributor notes for the existing code rules and inspect TestDeviceHoldAllocationFailure in clean/fsr/tests/test_frontend.cpp. Done means all identified sites follow the proposed rule, the rule is documented, and the relevant throwing-copy test passes in the CI configuration.

由索引模型根据 Issue 内容生成。

描述

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; #225 does this: DeviceRelease in clean/fsr/src/async_create.h), or
  • a capture whose copy cannot throw: a raw pointer, an index, a std::shared_ptr (copy is noexcept), or a std::move into an init-capture of a type with a noexcept move.

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.
主要语言
C++
星标
12
派生
2
平均合并
3 小时 10 分钟
30 天内合并 PR
171

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

phantoslayer21/wronggpu 的其他 Issue

查看 phantoslayer21/wronggpu 的全部 Issue

相似的 Issue

更多 C++ Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。