Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

- Avoid sending despawn for entities that weren't sent.
- Avoid panicking when `Signature` inserted during replication.

### Removed

Expand Down
22 changes: 18 additions & 4 deletions src/shared/replication/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,14 +307,22 @@ fn register_hash(mut world: DeferredWorld, ctx: HookContext) {
let mut signature = entity.get_mut::<Signature>().unwrap();
signature.hash = hash;

world
.resource_mut::<SignatureMap>()
.insert(ctx.entity, hash);
if let Some(mut map) = world.get_resource_mut::<SignatureMap>() {
map.insert(ctx.entity, hash);
} else {
// Can't be handled manually like with unregistering below.
// However, when it's inserted during replication, entities
// don't need to be mapped. For example, the signature could
// be a required component to map local player entities,
// but ignored for remote ones.
debug!("ignoring hash 0x{hash:016x} for `{}`", ctx.entity);
}
}

fn unregister_hash(mut world: DeferredWorld, ctx: HookContext) {
// The map will be unavailable during replication because the
// resource will be temporarily removed from the world.
// resource will be temporarily removed from the world,
// so it's handled manually there.
if let Some(mut map) = world.get_resource_mut::<SignatureMap>() {
map.remove(ctx.entity);
}
Expand Down Expand Up @@ -395,6 +403,12 @@ variadics_please::all_tuples!(impl_signature_components, 0, 6, C);
mod tests {
use super::*;

#[test]
fn no_panic_without_map() {
let mut world = World::new();
world.spawn(Signature::from(0)).despawn();
}

#[test]
fn single_component() {
let mut world = World::new();
Expand Down