Skip to content

Commit 960af2b

Browse files
robtfmcart
authored andcommitted
try_insert Aabbs (#10801)
# Objective avoid panics from `calculate_bounds` systems if entities are despawned in PostUpdate. there's a running general discussion (#10166) about command panicking. in the meantime we may as well fix up some cases where it's clear a failure to insert is safe. ## Solution change `.insert(aabb)` to `.try_insert(aabb)`
1 parent 220b08d commit 960af2b

File tree

2 files changed

+4
-4
lines changed
  • crates

2 files changed

+4
-4
lines changed

crates/bevy_render/src/view/visibility/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ pub fn calculate_bounds(
269269
for (entity, mesh_handle) in &without_aabb {
270270
if let Some(mesh) = meshes.get(mesh_handle) {
271271
if let Some(aabb) = mesh.compute_aabb() {
272-
commands.entity(entity).insert(aabb);
272+
commands.entity(entity).try_insert(aabb);
273273
}
274274
}
275275
}

crates/bevy_sprite/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ pub fn calculate_bounds_2d(
131131
for (entity, mesh_handle) in &meshes_without_aabb {
132132
if let Some(mesh) = meshes.get(&mesh_handle.0) {
133133
if let Some(aabb) = mesh.compute_aabb() {
134-
commands.entity(entity).insert(aabb);
134+
commands.entity(entity).try_insert(aabb);
135135
}
136136
}
137137
}
@@ -144,7 +144,7 @@ pub fn calculate_bounds_2d(
144144
center: (-sprite.anchor.as_vec() * size).extend(0.0).into(),
145145
half_extents: (0.5 * size).extend(0.0).into(),
146146
};
147-
commands.entity(entity).insert(aabb);
147+
commands.entity(entity).try_insert(aabb);
148148
}
149149
}
150150
for (entity, atlas_sprite, atlas_handle) in &atlases_without_aabb {
@@ -158,7 +158,7 @@ pub fn calculate_bounds_2d(
158158
center: (-atlas_sprite.anchor.as_vec() * size).extend(0.0).into(),
159159
half_extents: (0.5 * size).extend(0.0).into(),
160160
};
161-
commands.entity(entity).insert(aabb);
161+
commands.entity(entity).try_insert(aabb);
162162
}
163163
}
164164
}

0 commit comments

Comments
 (0)