Skip to content

Commit 03ee959

Browse files
authored
Fix panic on Text UI without Cameras (#11405)
# Objective Fix #11396. ## Solution Don't panic on taffy node not existing. Plus minor warning text improvement.
1 parent 056b006 commit 03ee959

File tree

1 file changed

+11
-6
lines changed
  • crates/bevy_ui/src/layout

1 file changed

+11
-6
lines changed

crates/bevy_ui/src/layout/mod.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,15 @@ impl UiSurface {
102102
}
103103
}
104104

105-
/// Update the `MeasureFunc` of the taffy node corresponding to the given [`Entity`].
106-
pub fn update_measure(&mut self, entity: Entity, measure_func: taffy::node::MeasureFunc) {
107-
let taffy_node = self.entity_to_taffy.get(&entity).unwrap();
108-
self.taffy.set_measure(*taffy_node, Some(measure_func)).ok();
105+
/// Update the `MeasureFunc` of the taffy node corresponding to the given [`Entity`] if the node exists.
106+
pub fn try_update_measure(
107+
&mut self,
108+
entity: Entity,
109+
measure_func: taffy::node::MeasureFunc,
110+
) -> Option<()> {
111+
let taffy_node = self.entity_to_taffy.get(&entity)?;
112+
113+
self.taffy.set_measure(*taffy_node, Some(measure_func)).ok()
109114
}
110115

111116
/// Update the children of the taffy node corresponding to the given [`Entity`].
@@ -305,7 +310,7 @@ pub fn ui_layout_system(
305310
Some(camera_entity) => {
306311
let Ok((_, camera)) = cameras.get(camera_entity) else {
307312
warn!(
308-
"TargetCamera is pointing to a camera {:?} which doesn't exist",
313+
"TargetCamera (of root UI node {entity:?}) is pointing to a camera {:?} which doesn't exist",
309314
camera_entity
310315
);
311316
continue;
@@ -356,7 +361,7 @@ pub fn ui_layout_system(
356361
}
357362
for (entity, mut content_size) in &mut measure_query {
358363
if let Some(measure_func) = content_size.measure_func.take() {
359-
ui_surface.update_measure(entity, measure_func);
364+
ui_surface.try_update_measure(entity, measure_func);
360365
}
361366
}
362367

0 commit comments

Comments
 (0)