Skip to content

Commit 0027011

Browse files
fix: More defensive programming
to avoid panics
1 parent f9c500e commit 0027011

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

crates/bevy_editor_pls_default_windows/src/cameras/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ fn set_main_pass_viewport(
604604
}
605605
});
606606

607-
cameras.iter_mut().for_each(|mut cam| {
608-
cam.viewport = viewport.clone();
609-
});
607+
cameras
608+
.iter_mut()
609+
.for_each(|mut cam| cam.viewport.clone_from(&viewport));
610610
}

crates/bevy_editor_pls_default_windows/src/gizmos.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,15 @@ impl EditorWindow for GizmoWindow {
6969
entities: Query<Entity, (With<EntityShouldShowGizmo>, Without<GizmoTarget>)>,
7070
) {
7171
for entity in entities.iter() {
72+
if let Some(mut entity) = commands.get_entity(entity) {
7273
trace!(
7374
"Hydrating a gizmo on entity {:?} because it is selected",
74-
entity
75+
entity.id()
7576
);
76-
// implicitly assumes it is the only gizmo system in the world,
77+
// implicitly assumes it is the only gizmo target in the world,
7778
// otherwise setting [GizmoTarget].is_focussed may be necessary
78-
commands.entity(entity).insert(GizmoTarget::default());
79+
entity.insert(GizmoTarget::default());
80+
}
7981
}
8082
}
8183

@@ -85,11 +87,13 @@ impl EditorWindow for GizmoWindow {
8587
entities: Query<Entity, (With<GizmoTarget>, Without<EntityShouldShowGizmo>)>,
8688
) {
8789
for entity in entities.iter() {
88-
commands.entity(entity).remove::<GizmoTarget>();
89-
debug!(
90-
"Removing GizmoTarget from entity {:?} because it has lost focus",
91-
entity
92-
);
90+
if let Some(mut entity) = commands.get_entity(entity) {
91+
entity.remove::<GizmoTarget>();
92+
debug!(
93+
"Removing GizmoTarget from entity {:?} because it has lost focus",
94+
entity.id()
95+
);
96+
}
9397
}
9498
}
9599

@@ -101,7 +105,9 @@ impl EditorWindow for GizmoWindow {
101105

102106
let selected_entities = hierarchy_state.selected.iter();
103107
for entity in selected_entities {
104-
world.entity_mut(entity).insert(EntityShouldShowGizmo);
108+
if let Some(mut entity) = world.get_entity_mut(entity) {
109+
entity.insert(EntityShouldShowGizmo);
110+
}
105111
}
106112

107113
world.run_system_once(hydrate_gizmos);
@@ -230,4 +236,4 @@ fn add_gizmo_markers(
230236
));
231237
});
232238
}
233-
}
239+
}

0 commit comments

Comments
 (0)