summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorLibravatar Billy Messenger <BillyDM@protonmail.com>2020-12-16 10:03:51 -0600
committerLibravatar Billy Messenger <BillyDM@protonmail.com>2020-12-16 10:03:51 -0600
commit4e391013c8bf8544fb766bee5dbae10cfdbc9d93 (patch)
tree5272b3d3588a01913854ce4b6e88380909a2a062 /examples
parenta42b3c6998274e75fd10f5ff3cecbdb37b9e3895 (diff)
downloadiced-4e391013c8bf8544fb766bee5dbae10cfdbc9d93.tar.gz
iced-4e391013c8bf8544fb766bee5dbae10cfdbc9d93.tar.bz2
iced-4e391013c8bf8544fb766bee5dbae10cfdbc9d93.zip
don't panic when swapchain frame is outdated
Diffstat (limited to 'examples')
-rw-r--r--examples/integration/src/main.rs97
1 files changed, 53 insertions, 44 deletions
diff --git a/examples/integration/src/main.rs b/examples/integration/src/main.rs
index 9b52f3a5..88d8d023 100644
--- a/examples/integration/src/main.rs
+++ b/examples/integration/src/main.rs
@@ -168,55 +168,64 @@ pub fn main() {
resized = false;
}
- let frame = swap_chain.get_current_frame().expect("Next frame");
+ match swap_chain.get_current_frame() {
+ Ok(frame) => {
+ let mut encoder = device.create_command_encoder(
+ &wgpu::CommandEncoderDescriptor { label: None },
+ );
- let mut encoder = device.create_command_encoder(
- &wgpu::CommandEncoderDescriptor { label: None },
- );
+ let program = state.program();
+
+ {
+ // We clear the frame
+ let mut render_pass = scene.clear(
+ &frame.output.view,
+ &mut encoder,
+ program.background_color(),
+ );
+
+ // Draw the scene
+ scene.draw(&mut render_pass);
+ }
+
+ // And then iced on top
+ let mouse_interaction = renderer.backend_mut().draw(
+ &mut device,
+ &mut staging_belt,
+ &mut encoder,
+ &frame.output.view,
+ &viewport,
+ state.primitive(),
+ &debug.overlay(),
+ );
- let program = state.program();
+ // Then we submit the work
+ staging_belt.finish();
+ queue.submit(Some(encoder.finish()));
- {
- // We clear the frame
- let mut render_pass = scene.clear(
- &frame.output.view,
- &mut encoder,
- program.background_color(),
- );
+ // Update the mouse cursor
+ window.set_cursor_icon(
+ iced_winit::conversion::mouse_interaction(
+ mouse_interaction,
+ ),
+ );
- // Draw the scene
- scene.draw(&mut render_pass);
- }
+ // And recall staging buffers
+ local_pool
+ .spawner()
+ .spawn(staging_belt.recall())
+ .expect("Recall staging buffers");
- // And then iced on top
- let mouse_interaction = renderer.backend_mut().draw(
- &mut device,
- &mut staging_belt,
- &mut encoder,
- &frame.output.view,
- &viewport,
- state.primitive(),
- &debug.overlay(),
- );
-
- // Then we submit the work
- staging_belt.finish();
- queue.submit(Some(encoder.finish()));
-
- // Update the mouse cursor
- window.set_cursor_icon(
- iced_winit::conversion::mouse_interaction(
- mouse_interaction,
- ),
- );
-
- // And recall staging buffers
- local_pool
- .spawner()
- .spawn(staging_belt.recall())
- .expect("Recall staging buffers");
-
- local_pool.run_until_stalled();
+ local_pool.run_until_stalled();
+ }
+ Err(error) => match error {
+ wgpu::SwapChainError::Outdated => {
+ // Try rendering again next frame.
+ window.request_redraw();
+ }
+ _ => panic!("Swapchain error: {:?}", error),
+ },
+ }
}
_ => {}
}