Skip to content

Commit 720b44f

Browse files
Add archetype rechecking when adding an untyped archetype invariant
1 parent 892f30a commit 720b44f

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

crates/bevy_ecs/src/world/archetype_invariants.rs

+21
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,27 @@ mod tests {
402402
world.add_archetype_invariant(ArchetypeInvariant::<(A, B, C)>::atomic());
403403
}
404404

405+
#[test]
406+
fn on_insert_untyped_happy() {
407+
let mut world = World::new();
408+
409+
world.spawn().insert_bundle((A, B, C));
410+
let archetype_invariant =
411+
ArchetypeInvariant::<(A, B, C)>::atomic().into_untyped(&mut world);
412+
world.add_untyped_archetype_invariant(archetype_invariant);
413+
}
414+
415+
#[test]
416+
#[should_panic]
417+
fn on_insert_untyped_sad() {
418+
let mut world = World::new();
419+
420+
world.spawn().insert_bundle((A, B));
421+
let archetype_invariant =
422+
ArchetypeInvariant::<(A, B, C)>::atomic().into_untyped(&mut world);
423+
world.add_untyped_archetype_invariant(archetype_invariant);
424+
}
425+
405426
#[test]
406427
fn forbids_happy() {
407428
let mut world = World::new();

crates/bevy_ecs/src/world/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,11 @@ impl World {
679679
&mut self,
680680
archetype_invariant: UntypedArchetypeInvariant,
681681
) {
682+
for archetype in &self.archetypes.archetypes {
683+
let components = archetype.components.indices();
684+
archetype_invariant.test_archetype(components);
685+
}
686+
682687
self.archetype_invariants.add(archetype_invariant);
683688
}
684689

0 commit comments

Comments
 (0)