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

Require read-only queries in QueryState::par_iter #8832

Merged
merged 1 commit into from
Jun 13, 2023

Conversation

JoJoJet
Copy link
Member

@JoJoJet JoJoJet commented Jun 12, 2023

Objective

The method QueryState::par_iter does not currently force the query to be read-only. This means you can unsoundly mutate a world through an immutable reference in safe code.

fn bad_system(world: &World, mut query: Local<QueryState<&mut T>>) {
    query.par_iter(world).for_each_mut(|mut x| *x = unsoundness);
}

Solution

Use read-only versions of the WorldQuery types.


Migration Guide

The function QueryState::par_iter now forces any world accesses to be read-only, similar to how QueryState::iter works. Any code that previously mutated the world using this method was unsound. If you need to mutate the world, use par_iter_mut instead.

@JoJoJet JoJoJet added C-Bug An unexpected or incorrect behavior 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 labels Jun 12, 2023
@JoJoJet JoJoJet requested a review from james7132 June 12, 2023 22:35
@alice-i-cecile alice-i-cecile added this to the 0.11 milestone Jun 12, 2023
@james7132 james7132 added the P-High This is particularly urgent, and deserves immediate attention label Jun 13, 2023
@james7132 james7132 added this pull request to the merge queue Jun 13, 2023
Merged via the queue into bevyengine:main with commit 3fba34c Jun 13, 2023
@JoJoJet JoJoJet deleted the par-iter-read-only branch June 13, 2023 01:43
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 C-Bug An unexpected or incorrect behavior M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide P-High This is particularly urgent, and deserves immediate attention P-Unsound A bug that results in undefined compiler behavior
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants