You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I tried to cleanup a system query, I made a full example here:
use bevy::{prelude::*, ecs::query::WorldQuery};#[derive(Component)]structMyComponent;fnmy_system0(mutquery:Query<&mutMyComponent,Changed<MyComponent>>){formut component in query.iter_mut(){// do something with component}}// so to clean it up I extract the query into a WorldQuery:#[derive(WorldQuery)]#[world_query(mutable)]structMyQuery1{entity:Entity,component:&'staticMyComponent,_a:Changed<MyComponent>,}fnmy_system1(mutquery:Query<MyQuery1>){formut component in query.iter_mut(){// do something with component}}// which works, however, this (with &mut) crashes with a runtime error:#[derive(WorldQuery)]#[world_query(mutable)]structMyQuery2{entity:Entity,component:&'staticmutMyComponent,// <- added mut_a:Changed<MyComponent>,}fnmy_system2(mutquery:Query<MyQuery2>){formut component in query.iter_mut(){// do something with component}}fnmain(){App::new().add_plugins(DefaultPlugins).add_systems(Update,(
my_system0,
my_system1,
my_system2,// <- runtime crash)).run();}
What went wrong
The error on my_system2 / MyQuery2 was '$state_name<bevy_minimal::MyComponent> conflicts with a previous access in this query. Shared access cannot coincide with exclusive access.'.
Backtrace:
thread 'main' panicked at '$state_name<bevy_minimal::MyComponent> conflicts with a previous access in this query. Shared access cannot coincide with exclusive access.', /home/apoc/.cargo/registry/src/index.crates.io-6f17d22bba15001f/bevy_ecs-0.11.3/src/query/filter.rs:600:1
stack backtrace:
0: rust_begin_unwind
at /rustc/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/std/src/panicking.rs:593:5
1: core::panicking::panic_fmt
at /rustc/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/core/src/panicking.rs:67:14
2: <bevy_ecs::query::filter::Changed<T> as bevy_ecs::query::fetch::WorldQuery>::update_component_access
at /home/apoc/.cargo/registry/src/index.crates.io-6f17d22bba15001f/bevy_ecs-0.11.3/src/query/filter.rs:536:21
3: bevy_minimal::_::<impl bevy_ecs::query::fetch::WorldQuery for bevy_minimal::MyQuery2>::update_component_access
at ./src/main.rs:26:10
4: bevy_ecs::query::state::QueryState<Q,F>::new
at /home/apoc/.cargo/registry/src/index.crates.io-6f17d22bba15001f/bevy_ecs-0.11.3/src/query/state.rs:102:9
5: <bevy_ecs::system::query::Query<Q,F> as bevy_ecs::system::system_param::SystemParam>::init_state
at /home/apoc/.cargo/registry/src/index.crates.io-6f17d22bba15001f/bevy_ecs-0.11.3/src/system/system_param.rs:169:21
6: <(P0,) as bevy_ecs::system::system_param::SystemParam>::init_state
at /home/apoc/.cargo/registry/src/index.crates.io-6f17d22bba15001f/bevy_ecs-0.11.3/src/system/system_param.rs:1384:21
7: <bevy_ecs::system::function_system::FunctionSystem<Marker,F> as bevy_ecs::system::system::System>::initialize
at /home/apoc/.cargo/registry/src/index.crates.io-6f17d22bba15001f/bevy_ecs-0.11.3/src/system/function_system.rs:483:33
8: bevy_ecs::schedule::schedule::ScheduleGraph::initialize
at /home/apoc/.cargo/registry/src/index.crates.io-6f17d22bba15001f/bevy_ecs-0.11.3/src/schedule/schedule.rs:849:21
9: bevy_ecs::schedule::schedule::Schedule::initialize
[...]
This only happens when I use "&mut MyComponent" with a "Changed", otherwise WorldQuery works as expected.
As an aside, I found those examples in custom_query_param.rs really difficult to understand but perhaps that's just me, at first I thought I was doing something wrong, or perhaps I am?
The text was updated successfully, but these errors were encountered:
Changed directly reads the change ticks of each component. &mut T will mutate them. This results in aliased access within a single query. Even in a filter position, this should panic due to the undefined behavior it would otherwise introduce, and it correctly does that. Even with #9918, this will still happen, and it is working as intended.
Bevy version
0.11.3
What you did
I tried to cleanup a system query, I made a full example here:
What went wrong
The error on my_system2 / MyQuery2 was '$state_name<bevy_minimal::MyComponent> conflicts with a previous access in this query. Shared access cannot coincide with exclusive access.'.
Backtrace:
This only happens when I use "&mut MyComponent" with a "Changed", otherwise WorldQuery works as expected.
This specific case is not mentioned in the examples: https://github.com/bevyengine/bevy/blob/main/examples/ecs/custom_query_param.rs
As an aside, I found those examples in custom_query_param.rs really difficult to understand but perhaps that's just me, at first I thought I was doing something wrong, or perhaps I am?
The text was updated successfully, but these errors were encountered: