runtime: keep present dump capture buffer across splash handoff #1738

Open
github-bot wants to merge 1 commit from github-bot/gh-1738 into main AGit
Owner

@⁠IlyassRS3 on GitHub · 2026-11-25 10:28 UTC · original
IlyassRS3:fix/present-dump-splash-handoff → main · +275 −19 · 5 files · 1 commits · open

Item ID: RT-PRESENT-DUMP-SPLASH-HANDOFF
Claim: #1608
Addresses finding: #1608 (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.
**@⁠IlyassRS3** on GitHub · 2026-11-25 10:28 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1738) `IlyassRS3:fix/present-dump-splash-handoff` → `main` · +275 −19 · 5 files · 1 commits · open Item ID: `RT-PRESENT-DUMP-SPLASH-HANDOFF` Claim: https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608 Addresses finding: https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608 (`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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:03:12 +00:00
Author
Owner

@⁠copilot-pull-request-reviewer[bot] on GitHub · 2026-11-25 10:28 UTC · original · reviewed

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

**@⁠copilot-pull-request-reviewer[bot]** on GitHub · 2026-11-25 10:28 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1738#pullrequestreview-6055855300) · **reviewed** Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
Author
Owner

@⁠lixonik on GitHub · 2026-11-25 10:34 UTC · original · reviewed

Independent native Windows A/B at 336e4ede against merge base 57ba40bd. I built the same PR vk_present_dump_test harness against both runtime trees and ran it through a real Vulkan swapchain. With --splash, the base wrote the splash PNG and then exited with 0xC0000005. The PR exited 0 and its PNG checks passed for all three captures, including the handoff. The standard, --default, and --invalid Vulkan cases and the CPU present_dump_test also passed on the PR.

AI-assisted testing. Synthetic textures only on one local Windows Vulkan setup.

**@⁠lixonik** on GitHub · 2026-11-25 10:34 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1738#pullrequestreview-6055947695) · **reviewed** Independent native Windows A/B at `336e4ede` against merge base `57ba40bd`. I built the same PR `vk_present_dump_test` harness against both runtime trees and ran it through a real Vulkan swapchain. With `--splash`, the base wrote the splash PNG and then exited with `0xC0000005`. The PR exited 0 and its PNG checks passed for all three captures, including the handoff. The standard, `--default`, and `--invalid` Vulkan cases and the CPU `present_dump_test` also passed on the PR. AI-assisted testing. Synthetic textures only on one local Windows Vulkan setup.
Author
Owner

@⁠abnalstlll-byte on GitHub · 2026-11-25 10:55 UTC · original · approved these changes

### Clean-Room & Technical Verification

  • Mergeability: 3-way merge against upstream main (bcaa13dad) is 100% clean with zero merge conflicts.
  • Clean-Room Compliance: 100% clean-room. Vulkan presenter lifecycle logic and synthetic tests only; zero retail files, game data, or keys (check_no_game_data.py clean).
  • Technical Rigor & Root Cause Fix:
    • VulkanPresenter::submit_now() previously unconditionally called release_capture() upon the first non-black title frame when splash_capture_only_ was set, leaving capture_ptr_ = nullptr while capture_size_ remained non-zero. Subsequent frame dumps dereferenced null into std::vector, triggering an access violation in ucrtbase.dll.
    • Added should_release_capture_after_splash(splash_capture_only, dump_.enabled()), ensuring capture_buffer_ and capture_ptr_ remain valid across splash dismissal whenever LEONIDA_PRESENT_DUMP is active.
    • Added overflow-safe buffer validation valid_frame_buffer().
    • Added portable CPU test present_dump_test and Vulkan lifecycle test vk_present_dump_test --splash.
    • Verified by independent native Vulkan A/B run (exited 0, all 3 PNGs matched).

LGTM! Approved.

**@⁠abnalstlll-byte** on GitHub · 2026-11-25 10:55 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1738#pullrequestreview-6056274360) · **approved these changes** ### Clean-Room & Technical Verification - **Mergeability**: 3-way merge against upstream `main` (`bcaa13dad`) is 100% clean with zero merge conflicts. - **Clean-Room Compliance**: 100% clean-room. Vulkan presenter lifecycle logic and synthetic tests only; zero retail files, game data, or keys (`check_no_game_data.py` clean). - **Technical Rigor & Root Cause Fix**: - `VulkanPresenter::submit_now()` previously unconditionally called `release_capture()` upon the first non-black title frame when `splash_capture_only_` was set, leaving `capture_ptr_ = nullptr` while `capture_size_` remained non-zero. Subsequent frame dumps dereferenced null into `std::vector`, triggering an access violation in `ucrtbase.dll`. - Added `should_release_capture_after_splash(splash_capture_only, dump_.enabled())`, ensuring `capture_buffer_` and `capture_ptr_` remain valid across splash dismissal whenever `LEONIDA_PRESENT_DUMP` is active. - Added overflow-safe buffer validation `valid_frame_buffer()`. - Added portable CPU test `present_dump_test` and Vulkan lifecycle test `vk_present_dump_test --splash`. - Verified by independent native Vulkan A/B run (exited 0, all 3 PNGs matched). LGTM! Approved.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1738/head:github-bot/gh-1738'
git switch 'github-bot/gh-1738'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1738'
git switch 'github-bot/gh-1738'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1738'
git switch 'github-bot/gh-1738'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1738'
git switch 'main'
git merge --squash 'github-bot/gh-1738'
git switch 'main'
git merge --ff-only 'github-bot/gh-1738'
git switch 'main'
git merge 'github-bot/gh-1738'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.