`World::clear_entities` causes observer logic to break safety
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 22h
- Merged PRs (30d)
- 161
Description
## Bevy version
0.14.1
## What you did
I keep an additional app in a non send resource (not a sub app) which is sent to an async compute task for physics rollback.
Before the task is started all entities are cleared
```
app.world_mut().clear_entities();
```
The app then updates once. `ScheduleRunnerPlugin` is not added to the app.
```
app.update();
```
Stack trace is here
[log.txt](https://github.com/user-attachments/files/16536112/log.txt)
If I replace `clear_entities()` with
```
loop {
let Some(entity) = app.world().iter_entities().next() else {
break;
};
let entity = entity.id();
app.world_mut().despawn(entity);
}
```
Then there is no panic.
## What went wrong
There is clearly a difference between calling `World::despawn` and `World::clear_entities`. Using the latter is causing the new observer logic to break safety in an unsafe block. Even if I'm not using bevy as intended here I shouldn't be able to do this with safe methods.
Contributor guide
Assessment
This issue has not been assessed yet.