From 570dec8b884c0fdbf1b77c2418e52e5699655976 Mon Sep 17 00:00:00 2001 From: Kelsi Date: Wed, 25 Feb 2026 03:45:13 -0800 Subject: [PATCH] Fix loading screen graphical artifacts on window resize Recreate Vulkan swapchain in LoadingScreen::render() when the dirty flag is set, so resizing the window during world loading no longer renders into a stale swapchain with mismatched framebuffers. --- include/rendering/loading_screen.hpp | 4 ++++ src/core/application.cpp | 1 + src/rendering/loading_screen.cpp | 10 ++++++++++ 3 files changed, 15 insertions(+) diff --git a/include/rendering/loading_screen.hpp b/include/rendering/loading_screen.hpp index 52f0ea08..5f119676 100644 --- a/include/rendering/loading_screen.hpp +++ b/include/rendering/loading_screen.hpp @@ -4,6 +4,8 @@ #include #include +struct SDL_Window; + namespace wowee { namespace rendering { @@ -27,11 +29,13 @@ public: // Must be set before initialize() for Vulkan texture upload void setVkContext(VkContext* ctx) { vkCtx = ctx; } + void setSDLWindow(SDL_Window* win) { sdlWindow = win; } private: bool loadImage(const std::string& path); VkContext* vkCtx = nullptr; + SDL_Window* sdlWindow = nullptr; // Vulkan texture for background image VkImage bgImage = VK_NULL_HANDLE; diff --git a/src/core/application.cpp b/src/core/application.cpp index 8e0d6c6b..9e34d7aa 100644 --- a/src/core/application.cpp +++ b/src/core/application.cpp @@ -3065,6 +3065,7 @@ void Application::loadOnlineWorldTerrain(uint32_t mapId, float x, float y, float // --- Loading screen for online mode --- rendering::LoadingScreen loadingScreen; loadingScreen.setVkContext(window->getVkContext()); + loadingScreen.setSDLWindow(window->getSDLWindow()); bool loadingScreenOk = loadingScreen.initialize(); auto showProgress = [&](const char* msg, float progress) { diff --git a/src/rendering/loading_screen.cpp b/src/rendering/loading_screen.cpp index 3511d8e3..34ad1aa6 100644 --- a/src/rendering/loading_screen.cpp +++ b/src/rendering/loading_screen.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -327,6 +328,15 @@ void LoadingScreen::render() { // Submit the frame to Vulkan (loading screen runs outside the main render loop) if (vkCtx) { + // Handle window resize: recreate swapchain before acquiring an image + if (vkCtx->isSwapchainDirty() && sdlWindow) { + int w = 0, h = 0; + SDL_GetWindowSize(sdlWindow, &w, &h); + if (w > 0 && h > 0) { + vkCtx->recreateSwapchain(w, h); + } + } + uint32_t imageIndex = 0; VkCommandBuffer cmd = vkCtx->beginFrame(imageIndex); if (cmd != VK_NULL_HANDLE) {