summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón <hector0193@gmail.com>2021-08-05 14:44:32 +0700
committerLibravatar GitHub <noreply@github.com>2021-08-05 14:44:32 +0700
commit45778ed598c0d202f8e86c47a444fd671fb3abce (patch)
treef0d7cd40b34bf4dca465fb6fd8fdeec5b0209e72 /examples
parent63bdbf817e0ecd8ce9162f2b8cc5eaefb5b42e68 (diff)
parent3e03a42bc69562639784a1b560978bf184576824 (diff)
downloadiced-45778ed598c0d202f8e86c47a444fd671fb3abce.tar.gz
iced-45778ed598c0d202f8e86c47a444fd671fb3abce.tar.bz2
iced-45778ed598c0d202f8e86c47a444fd671fb3abce.zip
Merge pull request #667 from BillyDM/wgpu_outdatedframe
Don't panic when wgpu swapchain frame is outdated
Diffstat (limited to 'examples')
-rw-r--r--examples/integration/src/main.rs99
1 files changed, 55 insertions, 44 deletions
diff --git a/examples/integration/src/main.rs b/examples/integration/src/main.rs
index b4f580a4..6f319466 100644
--- a/examples/integration/src/main.rs
+++ b/examples/integration/src/main.rs
@@ -172,55 +172,66 @@ 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::OutOfMemory => {
+ panic!("Swapchain error: {}. Rendering cannot continue.", error)
+ }
+ _ => {
+ // Try rendering again next frame.
+ window.request_redraw();
+ }
+ },
+ }
}
_ => {}
}