From 5666e8301eadb263db08aeedcf8b0fbe1e8b603f Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Fri, 14 Apr 2023 10:32:56 +0200 Subject: [PATCH] Log an error when a scene fails to build --- crates/gpui/src/app.rs | 21 ++++++++++----------- crates/gpui/src/app/window.rs | 8 ++++---- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/crates/gpui/src/app.rs b/crates/gpui/src/app.rs index f054552ea3..fbd83625a5 100644 --- a/crates/gpui/src/app.rs +++ b/crates/gpui/src/app.rs @@ -26,6 +26,7 @@ use anyhow::{anyhow, Context, Result}; use parking_lot::Mutex; use postage::oneshot; use smol::prelude::*; +use util::ResultExt; use uuid::Uuid; pub use action::*; @@ -1179,12 +1180,6 @@ impl AppContext { } } - pub(crate) fn name_for_view(&self, window_id: usize, view_id: usize) -> Option<&str> { - self.views - .get(&(window_id, view_id)) - .map(|view| view.ui_name()) - } - pub fn all_action_names<'a>(&'a self) -> impl Iterator + 'a { self.action_deserializers.keys().copied() } @@ -1448,7 +1443,9 @@ impl AppContext { })); let mut window = Window::new(window_id, platform_window, self, build_root_view); - let scene = WindowContext::mutable(self, &mut window, window_id).build_scene(); + let scene = WindowContext::mutable(self, &mut window, window_id) + .build_scene() + .expect("initial scene should not error"); window.platform_window.present_scene(scene); window } @@ -1758,8 +1755,9 @@ impl AppContext { if let Some(mut invalidation) = cx.window.invalidation.take() { let appearance = cx.window.platform_window.appearance(); cx.invalidate(&mut invalidation, appearance); - let scene = cx.build_scene(); - cx.window.platform_window.present_scene(scene); + if let Some(scene) = cx.build_scene().log_err() { + cx.window.platform_window.present_scene(scene); + } } }); } @@ -1835,8 +1833,9 @@ impl AppContext { .extend(cx.window.rendered_views.keys().copied()); cx.invalidate(&mut invalidation, cx.window.platform_window.appearance()); cx.refreshing = true; - let scene = cx.build_scene(); - cx.window.platform_window.present_scene(scene); + if let Some(scene) = cx.build_scene().log_err() { + cx.window.platform_window.present_scene(scene); + } }); } } diff --git a/crates/gpui/src/app/window.rs b/crates/gpui/src/app/window.rs index 41358ed374..c9008b551e 100644 --- a/crates/gpui/src/app/window.rs +++ b/crates/gpui/src/app/window.rs @@ -807,13 +807,13 @@ impl<'a: 'b, 'b> WindowContext<'a, 'b> { Ok(element) } - pub fn build_scene(&mut self) -> Scene { + pub fn build_scene(&mut self) -> Result { let window_size = self.window.platform_window.content_size(); let scale_factor = self.window.platform_window.scale_factor(); let root_view_id = self.window.root_view().id(); let mut rendered_root = self.window.rendered_views.remove(&root_view_id).unwrap(); - rendered_root.layout(SizeConstraint::strict(window_size), self); + rendered_root.layout(SizeConstraint::strict(window_size), self)?; let mut scene_builder = SceneBuilder::new(scale_factor); rendered_root.paint( @@ -821,7 +821,7 @@ impl<'a: 'b, 'b> WindowContext<'a, 'b> { Vector2F::zero(), RectF::from_points(Vector2F::zero(), window_size), self, - ); + )?; self.window .rendered_views .insert(root_view_id, rendered_root); @@ -837,7 +837,7 @@ impl<'a: 'b, 'b> WindowContext<'a, 'b> { } } - scene + Ok(scene) } pub fn rect_for_text_range(&self, range_utf16: Range) -> Option {