Open
Description
Bevy version
main (2078137)
What you did
I was messing around with some internal tests, and I found the following problem in relationship_source_collection.rs
#[test]
fn entity_index_map() {
#[derive(Component)]
#[relationship(relationship_target = RelTarget)]
struct Rel(Entity);
#[derive(Component)]
#[relationship_target(relationship = Rel, linked_spawn)]
struct RelTarget(EntityHashSet);
let mut world = World::new();
let _ = world.spawn_empty(); // <-- THIS WAS ADDED
let a = world.spawn_empty().id();
let b = world.spawn_empty().id();
let c = world.spawn_empty().id();
let d = world.spawn_empty().id();
world.entity_mut(a).add_related::<Rel>(&[b, c, d]);
let rel_target = world.get::<RelTarget>(a).unwrap();
let collection = rel_target.collection();
// Insertions should maintain ordering
assert!(collection.iter().eq(&[d, c, b])); // <-- THIS FAILS
world.entity_mut(c).despawn();
let rel_target = world.get::<RelTarget>(a).unwrap();
let collection = rel_target.collection();
// Removals should maintain ordering
assert!(collection.iter().eq(&[d, b]));
}
What went wrong
The assertion fails, and after some very crude debugging, I found that collection.iter()
returns
3v0#4294967292, 2v0#4294967293, 4v0#4294967291
instead of
4v0#4294967291, 3v0#4294967292, 2v0#4294967293
This leads me to believe that relationship ordering is not working correctly, if offsetting the entities by 1 can cause this.