Log an error when a scene fails to build

This commit is contained in:
Antonio Scandurra 2023-04-14 10:32:56 +02:00
parent 9ef79735dc
commit 5666e8301e
2 changed files with 14 additions and 15 deletions

View file

@ -26,6 +26,7 @@ use anyhow::{anyhow, Context, Result};
use parking_lot::Mutex; use parking_lot::Mutex;
use postage::oneshot; use postage::oneshot;
use smol::prelude::*; use smol::prelude::*;
use util::ResultExt;
use uuid::Uuid; use uuid::Uuid;
pub use action::*; 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<Item = &'static str> + 'a { pub fn all_action_names<'a>(&'a self) -> impl Iterator<Item = &'static str> + 'a {
self.action_deserializers.keys().copied() 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 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.platform_window.present_scene(scene);
window window
} }
@ -1758,8 +1755,9 @@ impl AppContext {
if let Some(mut invalidation) = cx.window.invalidation.take() { if let Some(mut invalidation) = cx.window.invalidation.take() {
let appearance = cx.window.platform_window.appearance(); let appearance = cx.window.platform_window.appearance();
cx.invalidate(&mut invalidation, appearance); cx.invalidate(&mut invalidation, appearance);
let scene = cx.build_scene(); if let Some(scene) = cx.build_scene().log_err() {
cx.window.platform_window.present_scene(scene); cx.window.platform_window.present_scene(scene);
}
} }
}); });
} }
@ -1835,8 +1833,9 @@ impl AppContext {
.extend(cx.window.rendered_views.keys().copied()); .extend(cx.window.rendered_views.keys().copied());
cx.invalidate(&mut invalidation, cx.window.platform_window.appearance()); cx.invalidate(&mut invalidation, cx.window.platform_window.appearance());
cx.refreshing = true; cx.refreshing = true;
let scene = cx.build_scene(); if let Some(scene) = cx.build_scene().log_err() {
cx.window.platform_window.present_scene(scene); cx.window.platform_window.present_scene(scene);
}
}); });
} }
} }

View file

@ -807,13 +807,13 @@ impl<'a: 'b, 'b> WindowContext<'a, 'b> {
Ok(element) Ok(element)
} }
pub fn build_scene(&mut self) -> Scene { pub fn build_scene(&mut self) -> Result<Scene> {
let window_size = self.window.platform_window.content_size(); let window_size = self.window.platform_window.content_size();
let scale_factor = self.window.platform_window.scale_factor(); let scale_factor = self.window.platform_window.scale_factor();
let root_view_id = self.window.root_view().id(); let root_view_id = self.window.root_view().id();
let mut rendered_root = self.window.rendered_views.remove(&root_view_id).unwrap(); 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); let mut scene_builder = SceneBuilder::new(scale_factor);
rendered_root.paint( rendered_root.paint(
@ -821,7 +821,7 @@ impl<'a: 'b, 'b> WindowContext<'a, 'b> {
Vector2F::zero(), Vector2F::zero(),
RectF::from_points(Vector2F::zero(), window_size), RectF::from_points(Vector2F::zero(), window_size),
self, self,
); )?;
self.window self.window
.rendered_views .rendered_views
.insert(root_view_id, rendered_root); .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<usize>) -> Option<RectF> { pub fn rect_for_text_range(&self, range_utf16: Range<usize>) -> Option<RectF> {