From 02048eab77b506ecbb3b08c38c8bb8cc920278d8 Mon Sep 17 00:00:00 2001 From: iris-ai <4+iris-ai@noreply.localhost> Date: Sun, 20 Sep 2026 01:00:05 -0400 Subject: [PATCH] Rebuild a suboptimal swapchain after presenting, not before `Surface::configure` panics while a texture the surface handed out is still alive, which wgpu says at both `configure` and `get_current_texture`. The `Suboptimal` arm configured with the texture it was about to draw with in hand, so the first suboptimal frame -- a resize or a display change on some drivers -- takes the app down instead of rebuilding the swapchain. The texture is good for this frame, so it is drawn with and presented, and the rebuild happens once `present` has consumed it. --- src/default/render.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/default/render.rs b/src/default/render.rs index 0004373..524b158 100644 --- a/src/default/render.rs +++ b/src/default/render.rs @@ -22,12 +22,12 @@ impl UiRenderer { } pub fn draw(&mut self) { - let output = match self.surface.get_current_texture() { - CurrentSurfaceTexture::Success(texture) => texture, - CurrentSurfaceTexture::Suboptimal(texture) => { - self.surface.configure(&self.device, &self.config); - texture - } + let (output, suboptimal) = match self.surface.get_current_texture() { + CurrentSurfaceTexture::Success(texture) => (texture, false), + // Used for this frame, and the swapchain rebuilt after it has + // been presented: configuring the surface while a texture it + // handed out is still alive panics. + CurrentSurfaceTexture::Suboptimal(texture) => (texture, true), CurrentSurfaceTexture::Outdated | CurrentSurfaceTexture::Lost => { self.surface.configure(&self.device, &self.config); return; @@ -60,6 +60,9 @@ impl UiRenderer { self.queue.submit(std::iter::once(encoder.finish())); self.window.pre_present_notify(); self.queue.present(output); + if suboptimal { + self.surface.configure(&self.device, &self.config); + } } pub fn resize(&mut self, size: &PhysicalSize) {