Skip to content

Commit 2ebab52

Browse files
authored
Prevent panic when despawning entities with NoAuto components (#608)
# Objective - This prevents a panic that can occur if an entity with one of the NoAuto components is despawned. - Fixes #607 ## Solution This solution to the problem just uses the non-panicking versions of retrieving an entity from the world and inserting a component in the on_remove_no_auto_mass_property function that runs when the component is removed. I think an argument could be made that this silently hides an issue of code trying to operate on an entity that no longer exists or that the on_remove shouldn't fire if it's happening because an entity is being despawned.
1 parent 5b80901 commit 2ebab52

File tree

1 file changed

+3
-4
lines changed
  • src/dynamics/rigid_body/mass_properties/components

1 file changed

+3
-4
lines changed

src/dynamics/rigid_body/mass_properties/components/mod.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -973,10 +973,9 @@ pub struct NoAutoCenterOfMass;
973973

974974
/// Triggers the recomputation of mass properties for rigid bodies when automatic computation is re-enabled.
975975
fn on_remove_no_auto_mass_property(mut world: DeferredWorld, entity: Entity, _id: ComponentId) {
976-
world
977-
.commands()
978-
.entity(entity)
979-
.insert(RecomputeMassProperties);
976+
if let Some(mut entity_commands) = world.commands().get_entity(entity) {
977+
entity_commands.try_insert(RecomputeMassProperties);
978+
}
980979
}
981980

982981
/// A marker component that forces the recomputation of [`ComputedMass`], [`ComputedAngularInertia`]

0 commit comments

Comments
 (0)