From 4e391013c8bf8544fb766bee5dbae10cfdbc9d93 Mon Sep 17 00:00:00 2001
From: Billy Messenger <BillyDM@protonmail.com>
Date: Wed, 16 Dec 2020 10:03:51 -0600
Subject: don't panic when swapchain frame is outdated

---
 examples/integration/src/main.rs | 97 ++++++++++++++++++++++------------------
 1 file changed, 53 insertions(+), 44 deletions(-)

(limited to 'examples/integration')

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),
+                    },
+                }
             }
             _ => {}
         }
-- 
cgit 


From a7d2834a6d15466eecca29bb6357d3539cb652cd Mon Sep 17 00:00:00 2001
From: Billy Messenger <BillyDM@tutamail.com>
Date: Thu, 22 Jul 2021 13:08:13 -0500
Subject: add custom error for Compositor::draw()

---
 examples/integration/src/main.rs | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

(limited to 'examples/integration')

diff --git a/examples/integration/src/main.rs b/examples/integration/src/main.rs
index ab0e2299..9ef31203 100644
--- a/examples/integration/src/main.rs
+++ b/examples/integration/src/main.rs
@@ -220,11 +220,13 @@ pub fn main() {
                         local_pool.run_until_stalled();
                     }
                     Err(error) => match error {
-                        wgpu::SwapChainError::Outdated => {
+                        wgpu::SwapChainError::OutOfMemory => {
+                            panic!("Swapchain error: {}. Rendering cannot continue.", error)
+                        }
+                        _ => {
                             // Try rendering again next frame.
                             window.request_redraw();
                         }
-                        _ => panic!("Swapchain error: {:?}", error),
                     },
                 }
             }
-- 
cgit