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) {