diff --git a/winit/src/lib.rs b/winit/src/lib.rs index 92007e56..b596573d 100644 --- a/winit/src/lib.rs +++ b/winit/src/lib.rs @@ -1009,10 +1009,35 @@ async fn run_instance
( present_span.finish(); } Err(error) => match error { - // This is an unrecoverable error. compositor::SurfaceError::OutOfMemory => { + // This is an unrecoverable error. panic!("{error:?}"); } + compositor::SurfaceError::Outdated + | compositor::SurfaceError::Lost => { + present_span.finish(); + + // Reconfigure surface and try redrawing + let physical_size = + window.state.physical_size(); + + if error == compositor::SurfaceError::Lost { + window.surface = current_compositor + .create_surface( + window.raw.clone(), + physical_size.width, + physical_size.height, + ); + } else { + current_compositor.configure_surface( + &mut window.surface, + physical_size.width, + physical_size.height, + ); + } + + window.raw.request_redraw(); + } _ => { present_span.finish();