Skip to content

Commit 2c5dadd

Browse files
committed
Fix incorrect locations after redundant spawn_column_batch_at
1 parent 88d43b1 commit 2c5dadd

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

src/world.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ impl World {
280280
// This entity ID was already assigned
281281
unsafe {
282282
if let Some(moved) = archetype.remove(index as u32, true) {
283-
self.entities.meta[moved as usize].location.index = moved;
283+
self.entities.meta[moved as usize].location.index = index as u32;
284284
}
285285
}
286286
continue;
@@ -1500,17 +1500,21 @@ mod tests {
15001500
// A column batch of two entities in the unit (no-component) archetype.
15011501
let mut batch = crate::ColumnBatchType::new();
15021502
batch.add::<String>();
1503-
let batch = batch.into_batch(2);
1503+
let batch = batch.into_batch(3);
15041504
{
15051505
let mut writer = batch.writer::<String>().unwrap();
15061506
writer.push("a".into()).unwrap();
15071507
writer.push("b".into()).unwrap();
1508+
writer.push("c".into()).unwrap();
15081509
}
15091510
let batch = batch.build().unwrap();
15101511

1511-
let e = Entity::from_bits(1 << 32).unwrap(); // id 0, generation 1
1512-
world.spawn_column_batch_at(&[e, e], batch); // the same handle twice
1513-
assert_eq!(world.iter().count(), 1);
1514-
assert_eq!(&*world.get::<&String>(e).unwrap(), "b");
1512+
let e0 = Entity::from_bits(1 << 32).unwrap(); // id 0, generation 1
1513+
let e1 = Entity::from_bits(1 << 32 | 1).unwrap(); // id 1, generation 1
1514+
world.spawn_column_batch_at(&[e1, e0, e1], batch); // the same handle twice
1515+
assert_eq!(world.len(), 2);
1516+
assert_eq!(world.iter().count(), 2);
1517+
assert_eq!(&*world.get::<&String>(e0).unwrap(), "b");
1518+
assert_eq!(&*world.get::<&String>(e1).unwrap(), "c");
15151519
}
15161520
}

0 commit comments

Comments
 (0)