`handle_client_disconnect` panics if an entity was manually despawned when a client disconnected
vladbat00 opened this issue · 4 comments
I accidentally triggered this by despawning an entity when handling a EventReader<DisconnectEvent>
event on the server side (at the time, I didn't know lightyear
already handled despawning).
You mean this system?
lightyear/lightyear/src/server/clients.rs
Line 73 in deec7e6
I'm surprised that it panics, there doesn't seem to be any part of the code that can panic.
Do you have a stacktrace?
Its prob just that controlled entities contains an invalid entity ref since he despawned it beforehand. The system doesnt account for this and simply derefs it with .entity (not get_entity)
Yeah, apologies, I didn't have the stacktrace as I forgot to save it and then changed my code.
handle_client_disconnect
calls commands.entity(*entity)
, which panics if an entity doesn't exist:
pub fn entity(&mut self, entity: Entity) -> EntityCommands {
#[inline(never)]
#[cold]
#[track_caller]
fn panic_no_entity(entity: Entity) -> ! {
panic!(
"Attempting to create an EntityCommands for entity {entity:?}, which doesn't exist.",
);
}
match self.get_entity(entity) {
Some(entity) => entity,
None => panic_no_entity(entity),
}
}
I hope this provides enough details, but if you still need a stacktrace, please let me know.
Thanks, I didn't realize that commands.entity()
could panic.
I fixed this, but only in the cb/0.16
branch (which tracks bevy 0.14)