Skip to content

Commit

Permalink
try_insert Aabbs (bevyengine#10801)
Browse files Browse the repository at this point in the history
# Objective

avoid panics from `calculate_bounds` systems if entities are despawned
in PostUpdate.

there's a running general discussion (bevyengine#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)`
  • Loading branch information
robtfm authored and james7132 committed Dec 1, 2023
1 parent f33235c commit e32ce0d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion crates/bevy_render/src/view/visibility/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ pub fn calculate_bounds(
for (entity, mesh_handle) in &without_aabb {
if let Some(mesh) = meshes.get(mesh_handle) {
if let Some(aabb) = mesh.compute_aabb() {
commands.entity(entity).insert(aabb);
commands.entity(entity).try_insert(aabb);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions crates/bevy_sprite/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ pub fn calculate_bounds_2d(
for (entity, mesh_handle) in &meshes_without_aabb {
if let Some(mesh) = meshes.get(&mesh_handle.0) {
if let Some(aabb) = mesh.compute_aabb() {
commands.entity(entity).insert(aabb);
commands.entity(entity).try_insert(aabb);
}
}
}
Expand All @@ -142,7 +142,7 @@ pub fn calculate_bounds_2d(
center: (-sprite.anchor.as_vec() * size).extend(0.0).into(),
half_extents: (0.5 * size).extend(0.0).into(),
};
commands.entity(entity).insert(aabb);
commands.entity(entity).try_insert(aabb);
}
}
for (entity, atlas_sprite, atlas_handle) in &atlases_without_aabb {
Expand All @@ -156,7 +156,7 @@ pub fn calculate_bounds_2d(
center: (-atlas_sprite.anchor.as_vec() * size).extend(0.0).into(),
half_extents: (0.5 * size).extend(0.0).into(),
};
commands.entity(entity).insert(aabb);
commands.entity(entity).try_insert(aabb);
}
}
}

0 comments on commit e32ce0d

Please sign in to comment.