Skip to content

Commit

Permalink
Don't panic when despawning entity multiple times (#649)
Browse files Browse the repository at this point in the history
Emit a debug log message instead of a panic when despawning an entity which has already been despawned.
  • Loading branch information
CleanCut committed Oct 8, 2020
1 parent ebce1f9 commit bf501b7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
- This allows drop-in use of colors from most applications.
- New methods `Color::rgb_linear` and `Color::rgba_linear` will accept colors already in linear sRGB (the old behavior)
- Individual color-components must now be accessed through setters and getters: `.r`, `.g`, `.b`, `.a`, `.set_r`, `.set_g`, `.set_b`, `.set_a`, and the corresponding methods with the `*_linear` suffix.
- Despawning an entity multiple times causes a debug-level log message to be emitted instead of a panic [649]

[552]: https://github.com/bevyengine/bevy/pull/552
[616]: https://github.com/bevyengine/bevy/pull/616
[649]: https://github.com/bevyengine/bevy/pull/649

## Version 0.2.1 (2020-9-20)

Expand Down
15 changes: 14 additions & 1 deletion crates/bevy_ecs/src/system/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ pub(crate) struct Despawn {

impl WorldWriter for Despawn {
fn write(self: Box<Self>, world: &mut World) {
world.despawn(self.entity).unwrap();
if let Err(e) = world.despawn(self.entity) {
log::debug!("Failed to despawn entity {:?}: {}", self.entity, e);
}
}
}

Expand Down Expand Up @@ -385,6 +387,7 @@ mod tests {
let mut command_buffer = Commands::default();
command_buffer.set_entity_reserver(world.get_entity_reserver());
command_buffer.spawn((1u32, 2u64));
let entity = command_buffer.current_entity().unwrap();
command_buffer.insert_resource(3.14f32);
command_buffer.apply(&mut world, &mut resources);
let results = world
Expand All @@ -394,5 +397,15 @@ mod tests {
.collect::<Vec<_>>();
assert_eq!(results, vec![(1u32, 2u64)]);
assert_eq!(*resources.get::<f32>().unwrap(), 3.14f32);
// test entity despawn
command_buffer.despawn(entity);
command_buffer.despawn(entity); // double despawn shouldn't panic
command_buffer.apply(&mut world, &mut resources);
let results2 = world
.query::<(&u32, &u64)>()
.iter()
.map(|(a, b)| (*a, *b))
.collect::<Vec<_>>();
assert_eq!(results2, vec![]);
}
}

0 comments on commit bf501b7

Please sign in to comment.