Skip to content
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

Make SystemParam::new_archetype and QueryState::new_archetype unsafe functions #13044

Merged
merged 1 commit into from
Apr 21, 2024

Conversation

james7132
Copy link
Member

Objective

Fix #2128. Both Query::new_archetype and SystemParam::new_archetype do not check if the Archetype comes from the same World the state is initialized from. This could result in unsoundness via invalid accesses if called incorrectly.

Solution

Make them unsafe functions and lift the invariant to the caller. This also caught one instance of us not validating the World in SystemState::update_archetypes_unsafe_world_cell's implementation.


Changelog

Changed: QueryState::new_archetype is now an unsafe function.
Changed: SystemParam::new_archetype is now an unsafe function.

Migration Guide

QueryState::new_archetype and SystemParam::new_archetype are now an unsafe functions that must be sure that the provided Archetype is from the same World that the state was initialized from. Callers may need to add additional assertions or propagate the safety invariant upwards through the callstack to ensure safety.

@james7132 james7132 added A-ECS Entities, components, systems, and events P-Unsound A bug that results in undefined compiler behavior labels Apr 20, 2024
@james7132 james7132 requested a review from joseph-gio April 20, 2024 21:00
@james7132 james7132 marked this pull request as ready for review April 20, 2024 21:00
@alice-i-cecile alice-i-cecile added M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide and removed M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide labels Apr 20, 2024
@james7132 james7132 added the M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide label Apr 20, 2024
@james7132 james7132 added this to the 0.14 milestone Apr 21, 2024
@james7132 james7132 added this pull request to the merge queue Apr 21, 2024
Merged via the queue into bevyengine:main with commit 54456b7 Apr 21, 2024
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ECS Entities, components, systems, and events M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide P-Unsound A bug that results in undefined compiler behavior
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add safety check in QueryState::new_archetype
3 participants