From e07983b7f6d8dbbe932ea7547ae54c1570a86f8e Mon Sep 17 00:00:00 2001 From: Pavel Okhlopkov Date: Fri, 10 Apr 2026 19:51:13 +0300 Subject: [PATCH] fix(rendering): crash on window resize due to stale swapchain MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Mark swapchain dirty in Application's SDL resize handler (was only done in Window::pollEvents which is never called) - Skip swapchain recreation when window is minimized (0×0 extent violates Vulkan spec and crashes vmaCreateImage) - Guard aspect ratio division by zero when height is 0 Signed-off-by: Pavel Okhlopkov --- src/core/application.cpp | 6 +++++- src/rendering/renderer.cpp | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/core/application.cpp b/src/core/application.cpp index 04ed7549..2a006a65 100644 --- a/src/core/application.cpp +++ b/src/core/application.cpp @@ -720,8 +720,12 @@ void Application::run() { int newWidth = event.window.data1; int newHeight = event.window.data2; window->setSize(newWidth, newHeight); + // Mark swapchain dirty so it gets recreated at the correct size + if (window->getVkContext()) { + window->getVkContext()->markSwapchainDirty(); + } // Vulkan viewport set in command buffer, not globally - if (renderer && renderer->getCamera()) { + if (renderer && renderer->getCamera() && newHeight > 0) { renderer->getCamera()->setAspectRatio(static_cast(newWidth) / newHeight); } // Notify addons so UI layouts can adapt to the new size diff --git a/src/rendering/renderer.cpp b/src/rendering/renderer.cpp index 8749a94e..3864ae1e 100644 --- a/src/rendering/renderer.cpp +++ b/src/rendering/renderer.cpp @@ -859,6 +859,8 @@ void Renderer::beginFrame() { // Handle swapchain recreation if needed if (vkCtx->isSwapchainDirty()) { + // Skip recreation while window is minimized (0×0 extent is a Vulkan spec violation) + if (window->getWidth() == 0 || window->getHeight() == 0) return; (void)vkCtx->recreateSwapchain(window->getWidth(), window->getHeight()); // Rebuild water resources that reference swapchain extent/views if (waterRenderer) {