Don't panic when despawning entity multiple times (#649)

Emit a debug log message instead of a panic when despawning an entity which has already been despawned.
This commit is contained in:
Nathan Stocks 2020-10-08 17:58:19 -06:00 committed by GitHub
parent ebce1f9c4a
commit bf501b77cc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 1 deletions

View file

@ -13,9 +13,11 @@
- This allows drop-in use of colors from most applications. - 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) - 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. - 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 [552]: https://github.com/bevyengine/bevy/pull/552
[616]: https://github.com/bevyengine/bevy/pull/616 [616]: https://github.com/bevyengine/bevy/pull/616
[649]: https://github.com/bevyengine/bevy/pull/649
## Version 0.2.1 (2020-9-20) ## Version 0.2.1 (2020-9-20)

View file

@ -72,7 +72,9 @@ pub(crate) struct Despawn {
impl WorldWriter for Despawn { impl WorldWriter for Despawn {
fn write(self: Box<Self>, world: &mut World) { 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);
}
} }
} }
@ -385,6 +387,7 @@ mod tests {
let mut command_buffer = Commands::default(); let mut command_buffer = Commands::default();
command_buffer.set_entity_reserver(world.get_entity_reserver()); command_buffer.set_entity_reserver(world.get_entity_reserver());
command_buffer.spawn((1u32, 2u64)); command_buffer.spawn((1u32, 2u64));
let entity = command_buffer.current_entity().unwrap();
command_buffer.insert_resource(3.14f32); command_buffer.insert_resource(3.14f32);
command_buffer.apply(&mut world, &mut resources); command_buffer.apply(&mut world, &mut resources);
let results = world let results = world
@ -394,5 +397,15 @@ mod tests {
.collect::<Vec<_>>(); .collect::<Vec<_>>();
assert_eq!(results, vec![(1u32, 2u64)]); assert_eq!(results, vec![(1u32, 2u64)]);
assert_eq!(*resources.get::<f32>().unwrap(), 3.14f32); 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![]);
} }
} }