From b21288bb1839070e6fef747a5f9d4ec4682c5e57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20B=C3=BCsch?= Date: Wed, 29 Apr 2026 20:56:28 +1000 Subject: [PATCH] Drop surface before reconfiguring it if texture is Suboptimal closes: #450 --- src/lib.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index e345d8a..6b02064 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -556,9 +556,14 @@ impl<'win> Pixels<'win> { match self.context.surface.get_current_texture() { CurrentSurfaceTexture::Success(surface_texture) => break surface_texture, - CurrentSurfaceTexture::Suboptimal(_) - | CurrentSurfaceTexture::Outdated - | CurrentSurfaceTexture::Lost => { + CurrentSurfaceTexture::Suboptimal(surface) => { + // It's important to drop the current surface before reconfiguring it, otherwise + // wgpu will panic. + // see https://github.com/parasyte/pixels/issues/450 + drop(surface); + self.reconfigure_surface(); + } + CurrentSurfaceTexture::Outdated | CurrentSurfaceTexture::Lost => { // Reconfigure the surface and retry immediately on any error. // See https://github.com/parasyte/pixels/issues/121 // See https://github.com/parasyte/pixels/issues/346