Skip to content

Commit

Permalink
Add archetype rechecking when adding an untyped archetype invariant
Browse files Browse the repository at this point in the history
  • Loading branch information
sixfold-origami committed Jul 2, 2022
1 parent 892f30a commit 720b44f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
21 changes: 21 additions & 0 deletions crates/bevy_ecs/src/world/archetype_invariants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,27 @@ mod tests {
world.add_archetype_invariant(ArchetypeInvariant::<(A, B, C)>::atomic());
}

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

world.spawn().insert_bundle((A, B, C));
let archetype_invariant =
ArchetypeInvariant::<(A, B, C)>::atomic().into_untyped(&mut world);
world.add_untyped_archetype_invariant(archetype_invariant);
}

#[test]
#[should_panic]
fn on_insert_untyped_sad() {
let mut world = World::new();

world.spawn().insert_bundle((A, B));
let archetype_invariant =
ArchetypeInvariant::<(A, B, C)>::atomic().into_untyped(&mut world);
world.add_untyped_archetype_invariant(archetype_invariant);
}

#[test]
fn forbids_happy() {
let mut world = World::new();
Expand Down
5 changes: 5 additions & 0 deletions crates/bevy_ecs/src/world/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,11 @@ impl World {
&mut self,
archetype_invariant: UntypedArchetypeInvariant,
) {
for archetype in &self.archetypes.archetypes {
let components = archetype.components.indices();
archetype_invariant.test_archetype(components);
}

self.archetype_invariants.add(archetype_invariant);
}

Expand Down

0 comments on commit 720b44f

Please sign in to comment.