[PR #1738] runtime: keep present dump capture buffer across splash handoff #1752

Open
opened 2026-11-26 21:18:50 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1738
Author: @IlyassRS3
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: fix/present-dump-splash-handoff


📝 Commits (1)

  • 336e4ed runtime: keep present dump capture buffer across splash handoff

📊 Changes

5 files changed (+275 additions, -19 deletions)

View changed files

📝 runtime/CMakeLists.txt (+13 -1)
📝 runtime/src/present_dump.h (+22 -1)
📝 runtime/src/vulkan_present.h (+21 -3)
➕ runtime/test/present_dump_test.cpp (+172 -0)
📝 runtime/test/vk_present_dump_test.cpp (+47 -14)

📄 Description

Item ID: RT-PRESENT-DUMP-SPLASH-HANDOFF
Claim: https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7159613942
Addresses finding: https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7157589788 (LEONIDA_PRESENT_DUMP access violation in ucrtbase.dll when the splash hands off to the first title frame)

Root cause

VulkanPresenter::present_splash() (runtime/src/vulkan_present_splash.h:16) sets splash_capture_only_ = enable_capture() when capture_ was false. On the first non-black title frame (show_title == true), VulkanPresenter::submit_now() (runtime/src/vulkan_present.h:648-655) unconditionally called release_capture() while dump_.enabled() was still true, setting capture_ptr_ = nullptr while leaving capture_size_ non-zero.

On the next dump_.due(shown - 1) frame (including the handoff frame itself if it falls on the interval, or the first post-handoff interval frame such as frame 150 at ,30 or 300 at ,150), dump_.save(..., capture_ptr_, size_t(capture_size_)) passed (nullptr, nullptr + capture_size_) to std::vector<std::uint8_t>, crashing with an access violation reading address 0 inside ucrtbase.dll (memcpy).

In addition, when !dump_.enabled(), release_capture() ran after finish_startup_frame() had waited only on the current ring slot's frame.done fence, without waiting on the other in-flight slot in frames_.

Changes

  • runtime/src/present_dump.h:
    • Added should_release_capture_after_splash(bool splash_capture_only, bool dump_enabled) (splash_capture_only && !dump_enabled).
    • Added overflow-safe valid_frame_buffer(extent, format, src, size, &needed).
    • Updated PresentDump::save() to validate via valid_frame_buffer() before copying src .. src + needed, disabling cleanly instead of dereferencing null or reading past size.
  • runtime/src/vulkan_present.h:
    • Keep capture_buffer_ / capture_ptr_ alive across splash handoff when dump_.enabled() is true (still clearing splash_capture_only_ and capture_ so only due dump frames copy via finish_image()).
    • When releasing the capture buffer after splash (!dump_.enabled()), wait on all frames_ fences before calling release_capture().
    • Reset capture_size_ = 0 in release_capture() and on vkCreateBuffer failure, and guard !capture_ptr_ || !capture_size_ before dump_.save().
  • runtime/test/present_dump_test.cpp & runtime/CMakeLists.txt:
    • Added portable CPU test present_dump_test covering should_release_capture_after_splash, valid_frame_buffer edge/overflow cases, and PresentDump::save() valid PNG + null/truncated/overflow/invalid-format guards.
  • runtime/test/vk_present_dump_test.cpp & runtime/CMakeLists.txt:
    • Added --splash mode (vk_present_dump_splash) exercising present_splash() -> present_blank() -> non-black title handoff present() on a due frame -> present_blank() -> present_planes(), checking validation_errors() == 0 and all 3 PNG outputs.

Verification

  • AI-assisted: yes
  • GPUs tested: none (developed on macOS without Windows SDK or Vulkan SDK)
  • Tested locally:
    • Compiled and ran runtime/test/present_dump_test.cpp with clang++ -std=c++20 -Wall -Wextra -Werror -O1 -g -fsanitize=address,undefined against a temporary local VkFormat/VkExtent2D stub (not committed): PASS.
    • Mutation test against main:runtime/src/present_dump.h passing (nullptr, 16) to PresentDump::save(): reproduced UBSan null-pointer arithmetic + ASan SEGV reading 0x0 (exit 134).
    • python3 -I scripts/check_no_game_data.py runtime/src/present_dump.h runtime/src/vulkan_present.h runtime/test/present_dump_test.cpp runtime/test/vk_present_dump_test.cpp runtime/CMakeLists.txt: PASS.
    • python3 -I tests/test_text_write_line_endings.py: 3/3 OK.
  • Not tested locally: runtime/src/vulkan_present.h and runtime/test/vk_present_dump_test.cpp (vk_present_dump_splash) are Win32/Vulkan and were not compiled or executed on macOS; they require Windows CI / a Vulkan GPU run.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/1738 **Author:** [@IlyassRS3](https://github.com/IlyassRS3) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/present-dump-splash-handoff` --- ### 📝 Commits (1) - [`336e4ed`](https://github.com/ubiquitarianism/leonida/commit/336e4edec844628c8cb35e1321f02e6e51911090) runtime: keep present dump capture buffer across splash handoff ### 📊 Changes **5 files changed** (+275 additions, -19 deletions) <details> <summary>View changed files</summary> 📝 `runtime/CMakeLists.txt` (+13 -1) 📝 `runtime/src/present_dump.h` (+22 -1) 📝 `runtime/src/vulkan_present.h` (+21 -3) ➕ `runtime/test/present_dump_test.cpp` (+172 -0) 📝 `runtime/test/vk_present_dump_test.cpp` (+47 -14) </details> ### 📄 Description Item ID: `RT-PRESENT-DUMP-SPLASH-HANDOFF` Claim: https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7159613942 Addresses finding: https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7157589788 (`LEONIDA_PRESENT_DUMP` access violation in `ucrtbase.dll` when the splash hands off to the first title frame) ## Root cause `VulkanPresenter::present_splash()` (`runtime/src/vulkan_present_splash.h:16`) sets `splash_capture_only_ = enable_capture()` when `capture_` was false. On the first non-black title frame (`show_title == true`), `VulkanPresenter::submit_now()` (`runtime/src/vulkan_present.h:648-655`) unconditionally called `release_capture()` while `dump_.enabled()` was still true, setting `capture_ptr_ = nullptr` while leaving `capture_size_` non-zero. On the next `dump_.due(shown - 1)` frame (including the handoff frame itself if it falls on the interval, or the first post-handoff interval frame such as frame 150 at `,30` or 300 at `,150`), `dump_.save(..., capture_ptr_, size_t(capture_size_))` passed `(nullptr, nullptr + capture_size_)` to `std::vector<std::uint8_t>`, crashing with an access violation reading address `0` inside `ucrtbase.dll` (`memcpy`). In addition, when `!dump_.enabled()`, `release_capture()` ran after `finish_startup_frame()` had waited only on the current ring slot's `frame.done` fence, without waiting on the other in-flight slot in `frames_`. ## Changes - **`runtime/src/present_dump.h`**: - Added `should_release_capture_after_splash(bool splash_capture_only, bool dump_enabled)` (`splash_capture_only && !dump_enabled`). - Added overflow-safe `valid_frame_buffer(extent, format, src, size, &needed)`. - Updated `PresentDump::save()` to validate via `valid_frame_buffer()` before copying `src .. src + needed`, disabling cleanly instead of dereferencing null or reading past `size`. - **`runtime/src/vulkan_present.h`**: - Keep `capture_buffer_` / `capture_ptr_` alive across splash handoff when `dump_.enabled()` is true (still clearing `splash_capture_only_` and `capture_` so only due dump frames copy via `finish_image()`). - When releasing the capture buffer after splash (`!dump_.enabled()`), wait on all `frames_` fences before calling `release_capture()`. - Reset `capture_size_ = 0` in `release_capture()` and on `vkCreateBuffer` failure, and guard `!capture_ptr_ || !capture_size_` before `dump_.save()`. - **`runtime/test/present_dump_test.cpp` & `runtime/CMakeLists.txt`**: - Added portable CPU test `present_dump_test` covering `should_release_capture_after_splash`, `valid_frame_buffer` edge/overflow cases, and `PresentDump::save()` valid PNG + null/truncated/overflow/invalid-format guards. - **`runtime/test/vk_present_dump_test.cpp` & `runtime/CMakeLists.txt`**: - Added `--splash` mode (`vk_present_dump_splash`) exercising `present_splash()` -> `present_blank()` -> non-black title handoff `present()` on a due frame -> `present_blank()` -> `present_planes()`, checking `validation_errors() == 0` and all 3 PNG outputs. ## Verification - **AI-assisted**: yes - **GPUs tested**: none (developed on macOS without Windows SDK or Vulkan SDK) - **Tested locally**: - Compiled and ran `runtime/test/present_dump_test.cpp` with `clang++ -std=c++20 -Wall -Wextra -Werror -O1 -g -fsanitize=address,undefined` against a temporary local `VkFormat`/`VkExtent2D` stub (not committed): **PASS**. - Mutation test against `main:runtime/src/present_dump.h` passing `(nullptr, 16)` to `PresentDump::save()`: reproduced UBSan null-pointer arithmetic + ASan SEGV reading `0x0` (`exit 134`). - `python3 -I scripts/check_no_game_data.py runtime/src/present_dump.h runtime/src/vulkan_present.h runtime/test/present_dump_test.cpp runtime/test/vk_present_dump_test.cpp runtime/CMakeLists.txt`: **PASS**. - `python3 -I tests/test_text_write_line_endings.py`: **3/3 OK**. - **Not tested locally**: `runtime/src/vulkan_present.h` and `runtime/test/vk_present_dump_test.cpp` (`vk_present_dump_splash`) are Win32/Vulkan and were not compiled or executed on macOS; they require Windows CI / a Vulkan GPU run. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#1752
No description provided.