projectharmonia / bevy_replicon

Server-authoritative networking crate for the Bevy game engine.
https://crates.io/crates/bevy_replicon
Apache License 2.0
346 stars 31 forks source link

Despawn failure should not panic #355

Open UkoeHB opened 4 hours ago

UkoeHB commented 4 hours ago

Reported on discord. If the server replicates an entity despawn but the entity was manually despawned on the client, replicon currently panics. It should not need to panic.

mirsella commented 3 hours ago
thread 'main' panicked at /home/mirsella/.local/share/cargo/registry/src/index.crates.io-6f17d22bba15001f/bevy_replicon-0.28.4/src/client.rs:429:45:
Entity Entity { index: 175, generation: 1 } does not exist
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Encountered a panic in system `bevy_replicon::client::ClientPlugin::receive_replication`!
Encountered a panic in system `bevy_app::main_schedule::Main::run_main`!

this correspond to

        // SAFETY: access is unique and used to obtain `EntityMut`, which is just a wrapper over `UnsafeEntityCell`.
        let mut client_entity: EntityMut =
            unsafe { world_cell.world_mut().entity_mut(client_entity).into() };

its entity_mut which panic as stated in its doc. is now here: https://github.com/projectharmonia/bevy_replicon/blob/0efa80723af57cac220cbf9ddbe30c08251b7220/src/core/replication/deferred_entity.rs#L23