Fix: Vulkan swapchain crashes on window resize, move, minimize and fullscreen #1001
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
GPU
GUI
help wanted
question
Shaders
Video
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/KytyPS5--KytyPS5!1001
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1001/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@Ekt0re on GitHub · 2026-10-03 11:44 UTC · original
Ekt0re:fix/swapchain-resize-and-minimize→main· +225 −40 · 3 files · 3 commits · closed without mergingFix Vulkan swapchain crashes on window resize, move, minimize and fullscreen
Root cause
On Windows, moving, resizing, minimizing or switching the window to fullscreen could bring down the whole emulator with a Vulkan validation error. Three independent problems were involved:
Swapchain::Create()passedsurface.capabilities.currentExtentstraight intoVkSwapchainCreateInfoKHR::imageExtentwithout checking it. When the window is minimized the compositor reports{0, 0}, whichvkCreateSwapchainKHR()rejects per spec:AcquireNextImage()returnedRecreateimmediately onVK_SUBOPTIMAL_KHR. A suboptimal acquire is still a successful acquire: them_image_acquired[m_frame_index]semaphore is signaled and has a pending operation that is never consumed by a submit. The swapchain was then recreated / re-acquired with that same semaphore, and also reused across frames without waiting for the previous submission that waits on it:Destroy()additionally only waited on the graphics queue (queue.waitIdle()), not on the whole device.window.cpp.WindowContext::Resize()hadEXIT_IF(new_width == 0 || new_height == 0), andProcessWindowEvent()cast the signed SDLdata1/data2touint32_twithout checking the sign, so a0or negative value could crash or wrap into a huge extent. Some window managers (Linux/macOS) can deliver{0, 0}size events while the window is hidden/iconified, so this path is reachable on other platforms too.Fixing only one of these would leave the crash reachable from another.
Fix
src/graphics/presentation/window/windowInternal.hstd::atomic_bool minimizedtoWindowContext, shared between the SDL event handling and the presentation code.src/graphics/presentation/window/window.cppResize(): theEXIT_IFis replaced by a guarded early return. A zero-sized request is logged, setsminimized = trueand keeps the last known-good size. A valid resize clears the flag.ProcessWindowEvent():HIDDENandMINIMIZEDsetminimized = true;RESTOREDandMAXIMIZEDclear it.RESIZED/PIXEL_SIZE_CHANGEDwith non-positivedata1/data2are ignored (logged, flagged as minimized). The cast touint32_tnow happens only after a> 0check, so a negative SDL value can no longer wrap into a huge extent.src/graphics/presentation/window/swapchain.cppStatus::Minimized,m_minimizedandIsMinimized().Create(): surface format negotiation now happens before the size checks, soFormat()is always valid. If the window is flagged as minimized, the drawable size is0, orcurrentExtentends up with a zero dimension,m_minimizedis set andCreate()returns beforevkCreateSwapchainKHR(no handle, images or semaphores are created).NeedsResize()now also reports a transition in/out of the minimized state, so the swapchain is rebuilt on restore.AcquireNextImage()/Present()returnStatus::Minimizedimmediately instead of calling into Vulkan with an invalid handle.Presenter::Implconstructor: if the window starts minimized (ImageCount() == 0) it falls back to a fixed frame-pool size of 3 instead of crashing inFramePool::Initialize().RecoverSwapchain()skipsframes.SetFormat()while minimized.Presenter::Impl::Present(): returns cleanly onMinimized(before and after acquire/recover/present) with no retry loop and no false "retry exhausted" error.m_frame_ticksvector stores the scheduler tick of the last submission for each frame index.Submit()records it.AcquireNextImage(CommandScheduler&)now waits on that tick before reusingm_image_acquired[m_frame_index], so the semaphore never has an uncompleted wait/signal when it is handed tovkAcquireNextImageKHR.VK_SUBOPTIMAL_KHRon acquire no longer aborts the frame. It is stored inm_suboptimal, the frame is rendered and presented normally (consuming the semaphore), andRecreateis returned fromPresent()afterwards.Destroy()now usesdevice.waitIdle()instead ofqueue.waitIdle()and resetsm_minimized/m_suboptimal.What this resolves
VUID-VkSwapchainCreateInfoKHR-imageExtent-01689crash on minimize.VUID-vkAcquireNextImageKHR-semaphore-01779crash on resize, window move and switching to fullscreen.EXIT_IFcrash inResize()on window managers delivering{0, 0}size events.Test
Tested on Windows by moving, resizing, minimizing/restoring and toggling fullscreen on the window, with all three present modes:
ImmediateMailboxFifoGames tested: Tetris, GTA Vice City (GTA Trilogy), Tomb Raider I-III Remastered, and others.
Result: no Vulkan validation errors, no crashes and no performance drops compared to the previous behavior.
AI Use
AI was used to analyze and study the problem, as well as to produce the final documentation. I personally reviewed and tested all of the code.
@coderabbitai[bot] on GitHub · 2026-10-03 11:54 UTC · original · edited 2026-10-03 13:49 UTC
Navigate logical layers of code changes, visualize relationships, and explore their blast radius.
📝 Walkthrough
Walkthrough
Window resize requests and events now update a minimized-state flag. Swapchain creation selects and validates a supported format before checking minimized state and drawable extent. Frame acquisition waits for the current frame slot’s submission tick. Presentation handles minimized states and defers recreation after a suboptimal acquisition.
Suggested reviewers:
nmzikPriority: ➖ Normal
Change: Bug fix
Merge Risk: ⚪ Minimal · up to
fa7adSwapchain recovery now waits for a usable surface extent, and the investigated resize event does not leave a restored window stuck minimized. No actionable merge-blocking risk remains from the supplied evidence.
Security Architecture Review
Security architecture risk: 🔵 Low · up to
fa7adThe change improves recovery from window changes without showing expanded permissions or external access. Risk remains low rather than minimal because completion of display operations before resource cleanup is not fully established.
Retained concerns
No architecture-level concerns identified.
Security review details
Security Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
Hardening Proposals
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share
Comment
@coderabbitai helpto get the list of available commands.@ -494,0 +542,4 @@// TODO: waitIdle() does not guarantee the presentation engine has finished consuming the last// present. Fully safe teardown would require per-present fences via// VK_KHR_swapchain_maintenance1.RequireVulkanSuccess(graphics.device.waitIdle(), "wait for swapchain device idle");@coderabbitai[bot] on GitHub · 2026-10-03 11:54 UTC · original · edited 2026-10-03 13:56 UTC
🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 2413
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 42892
🌐 Web query:
Vulkan specification vkDeviceWaitIdle vkQueuePresentKHR presentation completion present wait semaphore destruction VK_KHR_swapchain_maintenance1 guidance💡 Result:
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 9829
Wait for presentation completion before destroying swapchain resources.
Swapchain::Present()passesm_render_complete[m_image_index]toqueue.presentKHR().device.waitIdle()does not prove that the presentation engine has finished using it.Destroy()then destroys that semaphore and the swapchain. Add a presentation-completion mechanism, such as per-present fences fromVK_KHR_swapchain_maintenance1where supported, and wait for every outstanding present before destroying these resources.✅ Confirmed as addressed by @Ekt0re
@ -379,2 +406,3 @@case SDL_EVENT_WINDOW_HIDDEN:case SDL_EVENT_WINDOW_HIDDEN: {LOGF("Window %" PRIu32 " hidden\n", window_event.windowID);minimized.store(true, std::memory_order_release);@coderabbitai[bot] on GitHub · 2026-10-03 11:54 UTC · original · edited 2026-10-03 13:54 UTC
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 4558
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 23301
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 3730
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 3644
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 2944
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 2279
Clear
minimizedwhen a window is shown at a positive drawable size.SDL_EVENT_WINDOW_SHOWNdoes not clear the flag. If noRESTORED,MAXIMIZED, or positivePIXEL_SIZE_CHANGEDevent follows, the flag can remain true. The swapchain can then remain minimized, and presentation returns without displaying frames. Query the drawable size in the shown-event branch and callResize()when both dimensions are positive.Suggested fix
✅ Addressed in commits
9ba4dd5tofa7ad32@coderabbitai[bot] on GitHub · 2026-10-03 11:54 UTC · original · reviewed
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
0d4030b1-9b51-4982-ab54-5aeca0df63bb📥 Commits
Reviewing files that changed from the base of the PR and between
f53e5d2283and e8598646319be3e7e9ef56820ba48c3ed8d00257.📒 Files selected for processing (3)
src/graphics/presentation/window/swapchain.cppsrc/graphics/presentation/window/window.cppsrc/graphics/presentation/window/windowInternal.hIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
@coderabbitai[bot] on GitHub · 2026-10-03 12:18 UTC · original · reviewed
ℹ️ Review info
⚙️ Run configuration
0142ee9d-4858-4b07-a4ef-f5be46d4fef7📥 Commits
Reviewing files that changed from the base of the PR and between e8598646319be3e7e9ef56820ba48c3ed8d00257 and
9ba4dd5302.📒 Files selected for processing (3)
src/graphics/presentation/window/swapchain.cppsrc/graphics/presentation/window/window.cppsrc/graphics/presentation/window/windowInternal.hIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.
@Ekt0re on GitHub · 2026-10-03 13:23 UTC · original
@coderabbitai review
The two outside-diff comments (swapchain.cpp:585-586 and window.cpp:453-459) refer to
the previous revision. They were addressed in
ccbef5f:minimizedon RESTORED/MAXIMIZED.Please re-evaluate against the latest commit.
@coderabbitai[bot] on GitHub · 2026-10-03 13:32 UTC · original
⚠️ Action not completed
Already reviewed the last commit. Use
@coderabbitai full reviewto rerun a review of the entire changeset.@Ekt0re on GitHub · 2026-10-03 13:41 UTC · original
@coderabbitai full review
@coderabbitai[bot] on GitHub · 2026-10-03 13:41 UTC · original · edited 2026-10-03 13:49 UTC
✅ Action performed
Full review finished.
@coderabbitai[bot] on GitHub · 2026-10-03 13:46 UTC · original · reviewed
♻️ Duplicate comments (1)
ℹ️ Review info
⚙️ Run configuration
813cb902-5320-4686-a456-e5ae6071762b📥 Commits
Reviewing files that changed from the base of the PR and between
f53e5d2283andfa7ad32987.📒 Files selected for processing (3)
src/graphics/presentation/window/swapchain.cppsrc/graphics/presentation/window/window.cppsrc/graphics/presentation/window/windowInternal.hIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.
@ -379,2 +406,3 @@case SDL_EVENT_WINDOW_HIDDEN:case SDL_EVENT_WINDOW_HIDDEN: {LOGF("Window %" PRIu32 " hidden\n", window_event.windowID);minimized.store(true, std::memory_order_release);@Ekt0re on GitHub · 2026-10-03 13:54 UTC · original
@coderabbitai done
@ -494,0 +542,4 @@// TODO: waitIdle() does not guarantee the presentation engine has finished consuming the last// present. Fully safe teardown would require per-present fences via// VK_KHR_swapchain_maintenance1.RequireVulkanSuccess(graphics.device.waitIdle(), "wait for swapchain device idle");@Ekt0re on GitHub · 2026-10-03 13:56 UTC · original
@coderabbitai resolve
@Nmzik on GitHub · 2026-10-08 14:33 UTC · original
Zero-sized surface on minimize is fixed
Pull request closed