Panic in drop leads to a double drop on spawning a new entity
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 22h
- Merged PRs (30d)
- 161
Description
From https://github.com/bevyengine/bevy/issues/2597#issuecomment-892066719
I think this happens due to `Table::allocate` increasing the column length before the data is actually written.
I also have a test for this, based on https://github.com/bevyengine/bevy/pull/2848
```rust
#[test]
fn panic_in_despawn_followed_by_insert() {
let helper = DropTestHelper::new();
let res = panic::catch_unwind(|| {
let mut world = World::new();
let e1 = world.spawn(helper.make_component(true, 0)).id();
let _ = panic::catch_unwind(panic::AssertUnwindSafe(|| {
world.despawn(e1);
}));
world.spawn(helper.make_component(true, 1));
println!("Done inserting! Dropping world...");
});
let drop_log = helper.finish(res);
assert_eq!(
&*drop_log,
[
DropLogItem::Create(0),
DropLogItem::Drop(0),
DropLogItem::Create(1),
DropLogItem::Drop(1)
]
);
}
```
Contributor guide
Assessment
This issue has not been assessed yet.