From 84ef51f454e2ba4a6ec1cdd6939b694bbefbd0b7 Mon Sep 17 00:00:00 2001 From: Peiikai <339721950+peiikai@users.noreply.github.com> Date: Fri, 13 Nov 2026 15:35:35 -0600 Subject: [PATCH] Android: the window surface retry logged once per trip to the background While the app was in the background the swapchain rebuild tried to make the window surface every frame and logged each failure: about 60 lines a second on a Retroid Pocket 5 (700 lines in a few seconds at the home screen). Now the first failure is logged, and the return says how many tries there were. Co-Authored-By: Claude Opus 5.5 --- runtime/nvn/vulkan/device.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/runtime/nvn/vulkan/device.c b/runtime/nvn/vulkan/device.c index 3c4fe0030..f2229fc5c 100644 --- a/runtime/nvn/vulkan/device.c +++ b/runtime/nvn/vulkan/device.c @@ -1162,8 +1162,10 @@ static void create_swapchain(void) { // Android destroys the window's surface whenever another activity covers the app (the folder picker, the home screen) // and SDL makes a new one on return: the old VkSurfaceKHR is lost for good (VK_ERROR_SURFACE_LOST_KHR on every acquire, // a black screen). So each swapchain rebuild there makes the surface again from SDL's current window first; the old -// swapchain belongs to the old window and can't be passed on. False: no window right now (in the background). +// swapchain belongs to the old window and can't be passed on. False: no window right now (in the background). That +// is tried again every frame while the app is away, so it is logged once: the first try, and the count on return. static bool recreate_surface(void) { + static unsigned misses; for (uint32_t i = 0; i < g_vk.sc_count; i++) vkDestroyImageView(g_vk.dev, g_vk.sc_views[i], NULL); g_vk.sc_count = 0; if (g_vk.swapchain) vkDestroySwapchainKHR(g_vk.dev, g_vk.swapchain, NULL); @@ -1171,11 +1173,13 @@ static bool recreate_surface(void) { if (g_vk.surface) vkDestroySurfaceKHR(g_vk.inst, g_vk.surface, NULL); g_vk.surface = VK_NULL_HANDLE; if (!SDL_Vulkan_CreateSurface(window, g_vk.inst, NULL, &g_vk.surface)) { - LOG("[vk] no window surface yet: %s\n", SDL_GetError()); + if (!misses++) LOG("[vk] no window surface yet: %s (tried again each frame, not logged)\n", SDL_GetError()); g_vk.surface = VK_NULL_HANDLE; return false; } - LOG("[vk] window surface made again (the app was in the background)\n"); + if (misses) LOG("[vk] window surface made again (the app was in the background; %u tries without a window)\n", misses); + else LOG("[vk] window surface made again (the app was in the background)\n"); + misses = 0; return true; } #endif