-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Panic in PushChildren command #7201
Comments
I forgot to mention that in my application crash happens somewhere 50% of the time. So it must be related to race conditions or someting, aka whether Anyways, I've created as minimal of an example as I could: use bevy::prelude::*;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_startup_system(system)
.run();
}
fn system(mut commands: Commands) {
let entity = commands.spawn(());
let entity_id = entity.id();
entity.despawn_recursive();
commands.entity(entity_id).with_children(|it| {
it.spawn(());
});
} This example appears to be illogical but it simulates what can happen when multiple systems are running. Stacktrace is also identical. |
I found that this change seems to resolve this crash: impl Command for PushChildren {
fn write(mut self, world: &mut World) {
let Some(mut parent) = world.get_entity_mut(self.parent) else {
for child in self.children {
despawn_with_children_recursive(world, child);
}
return;
};
update_old_parents(world, self.parent, &self.children);
if let Some(mut children) = parent.get_mut::<Children>() {
children.0.retain(|child| !self.children.contains(child));
children.0.append(&mut self.children);
} else {
parent.insert(Children(self.children));
}
}
} I would also argue that Bevy probably should avoid using panicing methods ( IMHO it is much better to have some entity/sprite/mesh missing in game rather than game crashing alltogether. At least in this case it will not be an unexpected behaviour, as parent was despawned anyways. PS: unfortunatelly I can't find a way to implement this (at least as a temporary workaround) outside of the Bevy sources because both |
Bevy version - 0.9.1
What you did
I have a particle emitter
Component
which spawns particles as itsChildren
. It can alsodespawn_recursive
itself when no longer needed. I'll try to localize a crash in the coming days as it is hard to pinpoint what exactly causes a crash.What went wrong
'Entity 457v0 does not exist' panic.
Additional information
Crash happens here:
Full Backtrace
Suggestion
It probably happens when one system despawns a parent while other adds a child. In such cases I think child should be despawned automatically if parent was not found.
Also maybe it is better to use
get_entity_mut
withif let
instead ofentity_mut
to avoid such panics?The text was updated successfully, but these errors were encountered: