Skip to content

Commit

Permalink
fix: despawning a tree may corrupt the archetype index for other
Browse files Browse the repository at this point in the history
relations in the same tree
  • Loading branch information
ten3roberts committed Nov 8, 2024
1 parent e92527c commit 84747f2
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/archetypes.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use core::fmt::Formatter;

use alloc::{collections::BTreeMap, sync::Arc, vec::Vec};

use crate::{
Expand Down Expand Up @@ -255,6 +257,7 @@ impl Archetypes {
}
}

#[derive(Debug)]
pub(crate) struct ArchetypeRecord {
// arch_id: ArchetypeId,
cell_index: usize,
Expand All @@ -269,6 +272,14 @@ pub(crate) struct ArchetypeIndex {
components: BTreeMap<ComponentKey, ArchetypeRecords>,
}

impl std::fmt::Debug for ArchetypeIndex {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.debug_struct("ArchetypeIndex")
.field("components", &self.components)
.finish()
}
}

impl ArchetypeIndex {
pub(crate) fn new() -> Self {
Self {
Expand Down Expand Up @@ -339,7 +350,10 @@ impl ArchetypeIndex {
if key.is_relation() {
assert!(key.target.is_some());
self.components
.remove(&ComponentKey::new(dummy(), key.target));
.entry(ComponentKey::new(dummy(), key.target))
.and_modify(|v| {
v.remove(&arch_id);
});

self.unregister_relation(arch_id, ComponentKey::new(key.id(), Some(dummy())));
}
Expand Down

0 comments on commit 84747f2

Please sign in to comment.