From 4e391013c8bf8544fb766bee5dbae10cfdbc9d93 Mon Sep 17 00:00:00 2001 From: Billy Messenger Date: Wed, 16 Dec 2020 10:03:51 -0600 Subject: don't panic when swapchain frame is outdated --- winit/src/application.rs | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'winit') diff --git a/winit/src/application.rs b/winit/src/application.rs index d1a94864..f19526cb 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -311,27 +311,32 @@ async fn run_instance( viewport_version = current_viewport_version; } - let new_mouse_interaction = compositor.draw( + if let Ok(new_mouse_interaction) = compositor.draw( &mut renderer, &mut swap_chain, state.viewport(), state.background_color(), &primitive, &debug.overlay(), - ); + ) { + debug.render_finished(); - debug.render_finished(); + if new_mouse_interaction != mouse_interaction { + window.set_cursor_icon(conversion::mouse_interaction( + new_mouse_interaction, + )); - if new_mouse_interaction != mouse_interaction { - window.set_cursor_icon(conversion::mouse_interaction( - new_mouse_interaction, - )); - - mouse_interaction = new_mouse_interaction; - } + mouse_interaction = new_mouse_interaction; + } // TODO: Handle animations! // Maybe we can use `ControlFlow::WaitUntil` for this. + } else { + debug.render_finished(); + + // Rendering could not complete, try again next frame. + window.request_redraw(); + } } event::Event::WindowEvent { event: window_event, -- cgit From a7d2834a6d15466eecca29bb6357d3539cb652cd Mon Sep 17 00:00:00 2001 From: Billy Messenger Date: Thu, 22 Jul 2021 13:08:13 -0500 Subject: add custom error for Compositor::draw() --- winit/src/application.rs | 41 ++++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) (limited to 'winit') diff --git a/winit/src/application.rs b/winit/src/application.rs index 903d03e2..b04fc609 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -366,7 +366,7 @@ async fn run_instance( viewport_version = current_viewport_version; } - if let Ok(new_mouse_interaction) = compositor.draw( + match compositor.draw( &mut renderer, &mut swap_chain, state.viewport(), @@ -374,23 +374,34 @@ async fn run_instance( &primitive, &debug.overlay(), ) { - debug.render_finished(); + Ok(new_mouse_interaction) => { + debug.render_finished(); - if new_mouse_interaction != mouse_interaction { - window.set_cursor_icon(conversion::mouse_interaction( - new_mouse_interaction, - )); + if new_mouse_interaction != mouse_interaction { + window.set_cursor_icon( + conversion::mouse_interaction( + new_mouse_interaction, + ), + ); - mouse_interaction = new_mouse_interaction; - } - - // TODO: Handle animations! - // Maybe we can use `ControlFlow::WaitUntil` for this. - } else { - debug.render_finished(); + mouse_interaction = new_mouse_interaction; + } - // Rendering could not complete, try again next frame. - window.request_redraw(); + // TODO: Handle animations! + // Maybe we can use `ControlFlow::WaitUntil` for this. + } + Err(error) => match error { + window::CompositorDrawError::SwapchainOutdated(_) => { + debug.render_finished(); + + // Swapchain is outdated. Try rendering again next frame. + window.request_redraw(); + } + window::CompositorDrawError::FatalSwapchainError(e) => { + // Fatal swapchain error. Rendering cannot continue. + panic!("{}", e); + } + }, } } event::Event::WindowEvent { -- cgit From e5010b8ab87b2e30feea366396bc060c8e793d8d Mon Sep 17 00:00:00 2001 From: Billy Messenger Date: Thu, 22 Jul 2021 13:23:36 -0500 Subject: redo custom error for Compositor::draw() --- winit/src/application.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'winit') diff --git a/winit/src/application.rs b/winit/src/application.rs index b04fc609..1d32a5f3 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -391,16 +391,16 @@ async fn run_instance( // Maybe we can use `ControlFlow::WaitUntil` for this. } Err(error) => match error { - window::CompositorDrawError::SwapchainOutdated(_) => { + // This is an unrecoverable error. + window::SwapChainError::OutOfMemory => { + panic!("{}", error); + } + _ => { debug.render_finished(); - // Swapchain is outdated. Try rendering again next frame. + // Try rendering again next frame. window.request_redraw(); } - window::CompositorDrawError::FatalSwapchainError(e) => { - // Fatal swapchain error. Rendering cannot continue. - panic!("{}", e); - } }, } } -- cgit