From a7c9b0a9dfe5051a60763e123df47f4c16052e32 Mon Sep 17 00:00:00 2001 From: HampusM Date: Sun, 16 Jun 2024 18:24:37 +0200 Subject: fix(ecs): create new archetype when archetype lookup entry is empty --- ecs/src/component/storage.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'ecs/src/component') diff --git a/ecs/src/component/storage.rs b/ecs/src/component/storage.rs index f174ea9..237dd73 100644 --- a/ecs/src/component/storage.rs +++ b/ecs/src/component/storage.rs @@ -77,7 +77,7 @@ impl ComponentStorage .join(", ") ); - let archetypes_indices = self + let archetype_indices = self .archetype_lookup .entry(ArchetypeComponentsHash::new( components @@ -91,10 +91,16 @@ impl ComponentStorage vec![self.archetypes.len() - 1] }); + if archetype_indices.is_empty() { + self.archetypes.push(Archetype::default()); + + archetype_indices.push(self.archetypes.len() - 1); + } + let archetype = self .archetypes .get_mut( - archetypes_indices + archetype_indices .first() .copied() .expect("No archetype index found"), -- cgit v1.2.3-18-g5258