amethyst/legion

Chunk shows the incorrect archetype after adding entity components?

Nehliin opened this issue · 0 comments

(I am running 0.3.1 from crates.io) I ran into issues where my systems that use chunk iteration wouldn't see added components to an entity and behave strangely in general (I may have misunderstood something). Given this minimal example:

struct A;
struct B;
struct C;

#[system]
#[read_component(A)]
#[read_component(B)]
fn read(world: &SubWorld) {
    let mut query = <(Read<A>, Read<B>)>::query();
    println!("Chunk iter start");
    query.par_for_each_chunk(world, |chunk| {
        println!(
            "{:?} componetns",
            chunk.archetype().layout().component_types(),
        );
    });
    println!("Chunk iter end");
}

#[system]
#[read_component(A)]
#[read_component(B)]
fn add_component(world: &SubWorld, command: &mut CommandBuffer) {
    let mut query = <(Entity, Read<A>, Read<B>)>::query();
    query.iter(world).for_each(|(entity, _, _)| {
        command.add_component(*entity, C);
    })
}

fn main() {
    let mut world = World::default();
    world.extend(vec![(A, B)]);
    let mut resources = Resources::default();
    let mut schedule = Schedule::builder()
        .add_system(read_system())
        .add_system(add_component_system())
        .flush()
        .build();
    schedule.execute(&mut world, &mut resources);
    schedule.execute(&mut world, &mut resources);
}

I would expect the output to be:

Chunk iter start
[ComponentTypeId { type_id: TypeId { t: 9352981314895745994 }, name: "test_legion::A" }, ComponentTypeId { type_id: TypeId { t: 1644017882235174221 }, name: "test_legion::B" }] componetns
Chunk iter end
Chunk iter start
[ComponentTypeId { type_id: TypeId { t: 9352981314895745994 }, name: "test_legion::A" }, ComponentTypeId { type_id: TypeId { t: 1644017882235174221 }, name: "test_legion::B" }, ComponentTypeId { type_id: TypeId { t: <someid> }, name: "test_legion::C" },] componetns
Chunk iter end

The actual ouput is however:

Chunk iter start
[ComponentTypeId { type_id: TypeId { t: 9352981314895745994 }, name: "test_legion::A" }, ComponentTypeId { type_id: TypeId { t: 1644017882235174221 }, name: "test_legion::B" }] componetns
Chunk iter end
Chunk iter start
[ComponentTypeId { type_id: TypeId { t: 9352981314895745994 }, name: "test_legion::A" }, ComponentTypeId { type_id: TypeId { t: 1644017882235174221 }, name: "test_legion::B" }] componetns
[ComponentTypeId { type_id: TypeId { t: 9352981314895745994 }, name: "test_legion::A" }, ComponentTypeId { type_id: TypeId { t: 1644017882235174221 }, name: "test_legion::B" }] componetns
Chunk iter end

The query seemingly is yielding 2 chunks with identical archetype layouts. I presume this is a bug otherwise I would like to know how I can modify an entities components and 1. see the result in chunk iteration 2. not causing the system to iterate over more chunks than one chunk (in this case).