From d0941cef2e480f0dbe1674b145b0cfbc252d49a6 Mon Sep 17 00:00:00 2001 From: Keith Simmons Date: Tue, 28 Jan 2020 13:38:37 -0800 Subject: [PATCH] handle panics in renderer somewhat more gracefully --- src/window.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/window.rs b/src/window.rs index e02d08a..ec18558 100644 --- a/src/window.rs +++ b/src/window.rs @@ -171,11 +171,17 @@ pub fn ui_loop() { let frame_start = Instant::now(); if REDRAW_SCHEDULER.should_draw() { - skulpin_renderer.draw(&window, |canvas, coordinate_system_helper| { - if renderer.draw(canvas, coordinate_system_helper) { - handle_new_grid_size(window.inner_size(), &renderer) - } - }).ok(); + if let Err(err) = panic::catch_unwind(|| { + skulpin_renderer.draw(&window, |canvas, coordinate_system_helper| { + if renderer.draw(canvas, coordinate_system_helper) { + handle_new_grid_size(window.inner_size(), &renderer) + } + }).ok(); + }) { + println!("Render failed. Closing app"); + *control_flow = ControlFlow::Exit; + return; + } } *control_flow = ControlFlow::WaitUntil(frame_start + Duration::from_secs_f32(1.0 / 60.0));