From 2eae1e8804bb74dc78e0ee85fab06266e42bb8e4 Mon Sep 17 00:00:00 2001 From: Benjamin Hansen Date: Wed, 16 Oct 2024 18:28:24 -0600 Subject: [PATCH] fix #574 --- docs/beginner/tutorial2-surface/README.md | 36 ++++++++++++++--------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/docs/beginner/tutorial2-surface/README.md b/docs/beginner/tutorial2-surface/README.md index 7f593b5b..6a29dab0 100644 --- a/docs/beginner/tutorial2-surface/README.md +++ b/docs/beginner/tutorial2-surface/README.md @@ -466,27 +466,35 @@ We need to update the event loop again to call this method. We'll also call `upd ```rust // run() -event_loop.run(move |event, _, control_flow| { +event_loop.run(move |event, control_flow| { match event { // ... with the other WindowEvents - WindowEvent::RedrawRequested(window_id) if window_id == state.window().id() => { + WindowEvent::RedrawRequested => { + // This tells winit that we want another frame after this one + state.window().request_redraw(); + + if !surface_configured { + return; + } + state.update(); match state.render() { Ok(_) => {} - // Reconfigure the surface if lost - Err(wgpu::SurfaceError::Lost) => state.resize(state.size), + // Reconfigure the surface if it's lost or outdated + Err( + wgpu::SurfaceError::Lost | wgpu::SurfaceError::Outdated, + ) => state.resize(state.size), // The system is out of memory, we should probably quit - Err(wgpu::SurfaceError::OutOfMemory) => *control_flow = ControlFlow::Exit, - // All other errors (Outdated, Timeout) should be resolved by the next frame - Err(e) => eprintln!("{:?}", e), - } - } + Err(wgpu::SurfaceError::OutOfMemory) => { + log::error!("OutOfMemory"); + control_flow.exit(); + } - // ... at the end of the WindowEvent block - Event::AboutToWait => { - // RedrawRequested will only trigger once unless we manually - // request it. - state.window().request_redraw(); + // This happens when the a frame takes too long to present + Err(wgpu::SurfaceError::Timeout) => { + log::warn!("Surface timeout") + } + } } // ... }