-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
track_change_detection: Also track spawns/despawns #16047
track_change_detection: Also track spawns/despawns #16047
Conversation
crates/bevy_ecs/src/query/error.rs
Outdated
Self::NoSuchEntity(entity, world) => { | ||
#[cfg(feature = "track_change_detection")] | ||
{ | ||
if let Some(location) = world.entities().get_entity_spawned_despawned_by(entity) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is really cool.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really nice change, I think this philosophy should be extended to more areas of Bevy too (e.g., Component
s). However, there is a safety comment which I believe this change violates. Either the PR needs to be amended to satisfy the invariant, or a SAFETY
comment should be added to the field to indicate why it is safe.
crates/bevy_ecs/src/query/error.rs
Outdated
} | ||
#[cfg(not(feature = "track_change_detection"))] | ||
{ | ||
write!(f, "The entity {entity} does not exist") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be nice to include a hint here to enable track_change_detection
for a more detailed error message?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great idea; implemented. Should I note in the feature description (in Cargo.toml
) that this feature has a perf impact so people don't ship with it on?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that's a good idea. And like the tracing
filter level features, we should include a note saying library authors should not enable this feature on their published crates, as it removes the ability for end-users to choose themselves.
# Objective `flush_and_reserve_invalid_assuming_no_entities` was made for the old rendering world (which was reset every frame) and is usused since the 0.15 retained rendering world, but wasn't removed yet. It is pub, but is undocumented apart from the safety comment. ## Solution Remove `flush_and_reserve_invalid_assuming_no_entities` and the safety invariants this method required for `EntityMeta`, `EntityLocation`, `TableId` and `TableRow`. This reduces the amount of unsafe code & safety invariants and makes #16047 easier. ## Alternatives - Document `flush_and_reserve_invalid_assuming_no_entities` and keep it unchanged - Document `flush_and_reserve_invalid_assuming_no_entities` and change it to be based on `EntityMeta::INVALID` ## Migration Guide - exchange `Entities::flush_and_reserve_invalid_assuming_no_entities` for `reserve` and `flush_as_invalid` and notify us if that's insufficient --------- Co-authored-by: Benjamin Brienen <[email protected]>
451ffc3
to
85dc8ca
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fantastic. I've marked this as ready for review.
Really lovely. We definitely need to rename the feature, but that's for follow-up. @SpecificProtagonist once merge conflicts are resolved I'll press the button. |
…16846) # Objective - Modify a comment in the shader file to describe what the shader actually does - Fixes bevyengine#16830 ## Solution - Changed the comment. ## Testing - Testing is not relevant to fixing comments (as long as the comment is accurate) --------- Co-authored-by: Freya Pines <[email protected]> Co-authored-by: Freya Pines <[email protected]>
This is the correct rotation type :)
ebb872b
to
7278e94
Compare
CI is happy; I'm happy. Let's go: this looks so sweet. |
# Objective `flush_and_reserve_invalid_assuming_no_entities` was made for the old rendering world (which was reset every frame) and is usused since the 0.15 retained rendering world, but wasn't removed yet. It is pub, but is undocumented apart from the safety comment. ## Solution Remove `flush_and_reserve_invalid_assuming_no_entities` and the safety invariants this method required for `EntityMeta`, `EntityLocation`, `TableId` and `TableRow`. This reduces the amount of unsafe code & safety invariants and makes bevyengine#16047 easier. ## Alternatives - Document `flush_and_reserve_invalid_assuming_no_entities` and keep it unchanged - Document `flush_and_reserve_invalid_assuming_no_entities` and change it to be based on `EntityMeta::INVALID` ## Migration Guide - exchange `Entities::flush_and_reserve_invalid_assuming_no_entities` for `reserve` and `flush_as_invalid` and notify us if that's insufficient --------- Co-authored-by: Benjamin Brienen <[email protected]>
# Objective Expand `track_change_detection` feature to also track entity spawns and despawns. Use this to create better error messages. # Solution Adds `Entities::entity_get_spawned_or_despawned_by` as well as `{all entity reference types}::spawned_by`. This also removes the deprecated `get_many_entities_mut` & co (and therefore can't land in 0.15) because we don't yet have no Polonius. ## Testing Added a test that checks that the locations get updated and these updates are ordered correctly vs hooks & observers. --- ## Showcase Access location: ```rust let mut world = World::new(); let entity = world.spawn_empty().id(); println!("spawned by: {}", world.entity(entity).spawned_by()); ``` ``` spawned by: src/main.rs:5:24 ``` Error message (with `track_change_detection`): ```rust world.despawn(entity); world.entity(entity); ``` ``` thread 'main' panicked at src/main.rs:11:11: Entity 0v1#4294967296 was despawned by src/main.rs:10:11 ``` and without: ``` thread 'main' panicked at src/main.rs:11:11: Entity 0v1#4294967296 does not exist (enable `track_change_detection` feature for more details) ``` Similar error messages now also exists for `Query::get`, `World::entity_mut`, `EntityCommands` creation and everything that causes `B0003`, e.g. ``` error[B0003]: Could not insert a bundle (of type `MaterialMeshBundle<StandardMaterial>`) for entity Entity { index: 7, generation: 1 }, which was despawned by src/main.rs:10:11. See: https://bevyengine.org/learn/errors/#b0003 ``` --------- Co-authored-by: kurk070ff <[email protected]> Co-authored-by: Freya Pines <[email protected]> Co-authored-by: Freya Pines <[email protected]> Co-authored-by: Matty Weatherley <[email protected]>
Objective
Expand
track_change_detection
feature to also track entity spawns and despawns. Use this to create better error messages.Solution
Adds
Entities::entity_get_spawned_or_despawned_by
as well as{all entity reference types}::spawned_by
.This also removes the deprecated
get_many_entities_mut
& co (and therefore can't land in 0.15) because we don't yet have no Polonius.Testing
Added a test that checks that the locations get updated and these updates are ordered correctly vs hooks & observers.
Showcase
Access location:
Error message (with
track_change_detection
):and without:
Similar error messages now also exists for
Query::get
,World::entity_mut
,EntityCommands
creation and everything that causesB0003
, e.g.