mirror of
https://github.com/bevyengine/bevy
synced 2024-11-22 04:33:37 +00:00
Fix unsoundness in query component access (#1929)
Pretty much does what it says in the title lol
This commit is contained in:
parent
9b7ed18f72
commit
9657f58f6a
3 changed files with 19 additions and 0 deletions
|
@ -1071,6 +1071,13 @@ mod tests {
|
|||
world.query::<(&A, &mut A)>();
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn mut_and_ref_query_panic() {
|
||||
let mut world = World::new();
|
||||
world.query::<(&mut A, &A)>();
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn mut_and_mut_query_panic() {
|
||||
|
|
|
@ -206,6 +206,10 @@ unsafe impl<T: Component> FetchState for ReadState<T> {
|
|||
}
|
||||
|
||||
fn update_component_access(&self, access: &mut FilteredAccess<ComponentId>) {
|
||||
if access.access().has_write(self.component_id) {
|
||||
panic!("&{} conflicts with a previous access in this query. Shared access cannot coincide with exclusive access.",
|
||||
std::any::type_name::<T>());
|
||||
}
|
||||
access.add_read(self.component_id)
|
||||
}
|
||||
|
||||
|
@ -656,6 +660,10 @@ unsafe impl<T: Component> FetchState for ChangeTrackersState<T> {
|
|||
}
|
||||
|
||||
fn update_component_access(&self, access: &mut FilteredAccess<ComponentId>) {
|
||||
if access.access().has_write(self.component_id) {
|
||||
panic!("ChangeTrackers<{}> conflicts with a previous access in this query. Shared access cannot coincide with exclusive access.",
|
||||
std::any::type_name::<T>());
|
||||
}
|
||||
access.add_read(self.component_id)
|
||||
}
|
||||
|
||||
|
|
|
@ -501,6 +501,10 @@ macro_rules! impl_tick_filter {
|
|||
|
||||
#[inline]
|
||||
fn update_component_access(&self, access: &mut FilteredAccess<ComponentId>) {
|
||||
if access.access().has_write(self.component_id) {
|
||||
panic!("$state_name<{}> conflicts with a previous access in this query. Shared access cannot coincide with exclusive access.",
|
||||
std::any::type_name::<T>());
|
||||
}
|
||||
access.add_read(self.component_id);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue