From 3e53d4bde16434d7959ab7ac2b0a26f8ba9a8de8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 22 Oct 2026 22:59:29 +0200 Subject: [PATCH] Outputs: Don't let a removal skip the wait while the graphics come back The outputs were only marked live after deviceRestored(), so a Native_RemoveOutputAndWait() that came in while it was recreating their swapchains returned at once. On Android the surface could then be freed while a swapchain was being made on it (unplugging the TV as the app returns to the foreground). Mark them live before the queue is processed, so such a removal waits for the next frame. Co-Authored-By: Claude Opus 5.5 (1M context) --- UI/NativeApp.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index b6977aa5c8..f944aee7cb 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -995,10 +995,12 @@ bool NativeInitGraphics(GraphicsContext *graphicsContext) { g_screenManager->setUIContext(uiContext); g_screenManager->setPostRenderCallback(&CallbackPostRender, nullptr); + // Live before the queue is processed: a removal that comes in while the outputs' swapchains are being + // recreated has to wait for the next frame, as its surface may be gone once it returns. + SetOutputsLive(true); // An output removed while there was no device can't be recreated, its surface may be gone. ProcessOutputRequests(); g_screenManager->deviceRestored(g_draw); - SetOutputsLive(true); g_audioBackend = System_CreateAudioBackend(); if (g_audioBackend) {