From d4d1a931ddecbf75811161b07621085559380ea6 Mon Sep 17 00:00:00 2001 From: Mubelotix Date: Thu, 16 Nov 2023 01:17:45 +0100 Subject: [PATCH] Fix deadlock --- minecraft-server/src/world/ecs.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/minecraft-server/src/world/ecs.rs b/minecraft-server/src/world/ecs.rs index 143ee0f5..eb20c8b0 100644 --- a/minecraft-server/src/world/ecs.rs +++ b/minecraft-server/src/world/ecs.rs @@ -37,11 +37,12 @@ impl Entities { /// Observe entities in a chunk through a closure /// That closure will be applied to each entity, and the results will be returned in a vector pub(super) async fn observe_entities(&self, chunk: ChunkColumnPosition, mut observer: impl FnMut(&AnyEntity) -> Option) -> Vec { - let entities = self.chunks.read().await; - let Some(eids) = entities.get(&chunk) else {return Vec::new()}; + let entities = self.entities.read().await; + let chunks = self.chunks.read().await; + let Some(eids) = chunks.get(&chunk) else {return Vec::new()}; let mut results = Vec::with_capacity(eids.len()); for eid in eids { - if let Some(entity) = self.entities.read().await.get(eid) { + if let Some(entity) = entities.get(eid) { if let Some(r) = observer(entity) { results.push(r); }