Skip to content

Commit

Permalink
fix #574
Browse files Browse the repository at this point in the history
  • Loading branch information
sotrh committed Oct 17, 2024
1 parent 494f265 commit 2eae1e8
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions docs/beginner/tutorial2-surface/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
}
// ...
}
Expand Down

0 comments on commit 2eae1e8

Please sign in to comment.