bevyengine / bevyengine/bevy

World::flush is not being called properly

Open
#12,312 3 comments 0 reactions 0 assignees View on GitHub
A-ECS C-Bug
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 16h
Merged PRs (30d)
171

Description

`Entities::reserve_entities` is considered 100% safe as it can be accessed from `World::entities`, but returns an iterator that yields `Entity` values that are not valid until `World::flush_entities`, a safe `pub(crate)` function. As it currently stands, there is no safe way to use `Entities::reserve_entities` as it *must* be paired with an unsafe call to `Entities::flush`, or `Entites::flush_as_invalid`.

Likewise, there are zero internal uses of the function due to our current use of `flush_and_reserve_invalid_assuming_no_entities` in the render world (see #12144).

It may be best to just remove all of these functions to simplify the code, or come up with safe abstractions around this for external use, such as #11602.

Contributor guide

Open the contributing guide

Research direction

Start by tracing Entities::reserve_entities, World::entities, World::flush_entities, Entities::flush, and Entities::flush_as_invalid, including the render-world use of flush_and_reserve_invalid_assuming_no_entities and related issues #12144 and #11602. This needs a maintainer decision on whether to remove the functions or define a safe external abstraction before implementation can be considered done.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
game-dev
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.