From 5a257202d2f0cdafb67c39a80c612ddeca6a2eb4 Mon Sep 17 00:00:00 2001 From: 999pingGG Date: Sun, 21 Dec 2025 15:49:27 -0600 Subject: [PATCH] GPU: Better detection of surface destruction --- src/gpu/vulkan/SDL_gpu_vulkan.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/gpu/vulkan/SDL_gpu_vulkan.c b/src/gpu/vulkan/SDL_gpu_vulkan.c index 4f5b1f75f6..de6b3c2bea 100644 --- a/src/gpu/vulkan/SDL_gpu_vulkan.c +++ b/src/gpu/vulkan/SDL_gpu_vulkan.c @@ -9660,14 +9660,6 @@ static bool VULKAN_INTERNAL_OnWindowResize(void *userdata, SDL_Event *e) data->swapchainCreateHeight = e->window.data2; } -#ifdef SDL_PLATFORM_ANDROID - if (e->type == SDL_EVENT_DID_ENTER_BACKGROUND) { - data = VULKAN_INTERNAL_FetchWindowData(w); - data->needsSwapchainRecreate = true; - data->needsSurfaceRecreate = true; - } -#endif - return true; } @@ -10720,6 +10712,11 @@ static bool VULKAN_Submit( if (presentResult == VK_ERROR_OUT_OF_DATE_KHR) { presentData->windowData->needsSwapchainRecreate = true; } + } else if (presentResult == VK_ERROR_SURFACE_LOST_KHR) { + // Android can destroy the surface at any time when the app goes into the background, + // even after successfully acquiring a swapchain texture and before presenting it. + presentData->windowData->needsSwapchainRecreate = true; + presentData->windowData->needsSurfaceRecreate = true; } else { if (presentResult != VK_SUCCESS) { VULKAN_INTERNAL_ReleaseCommandBuffer(vulkanCommandBuffer);