Skip to content
This repository has been archived by the owner on Jul 1, 2024. It is now read-only.

Commit

Permalink
Fix deadlock
Browse files Browse the repository at this point in the history
  • Loading branch information
Mubelotix committed Nov 16, 2023
1 parent dde308a commit d4d1a93
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions minecraft-server/src/world/ecs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<R>(&self, chunk: ChunkColumnPosition, mut observer: impl FnMut(&AnyEntity) -> Option<R>) -> Vec<R> {
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);
}
Expand Down

0 comments on commit d4d1a93

Please sign in to comment.