#Bevy panics due to conflicting with previous resource access even though there is no duplicate

14 messages · Page 1 of 1 (latest)

nova sundial
#

when running this system (simplified here):

pub fn test(query: Query<EntityMut>, resource: Res<SomeResource>) {
    ...
}

bevy panics immediately after rust compiles, saying:

error[B0002]: Res<project::SomeResource> in system project::test conflicts with a previous ResMut<project::SomeResource> access. Consider removing the duplicate access.
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Encountered a panic in system `bevy_app::main_schedule::Main::run_main`!

is this a bug or is there something going on that I don't understand?

obsidian comet
#

B0002 (https://bevyengine.org/learn/errors/b0002/) is about access within the same system.

The error message seems to indicate that you have both Res<SomeResource> and ResMut<SomeResource> as parameters for that system, which isn't allowed.

You'll need to remove one of them.

nova sundial
obsidian comet
#

Yeah, okay, that's interesting. I'm not sure how you could end up with that particular error when that's the case, unless the access is being obfuscated by a custom SystemParam or something.

Are you 100% sure that's the correct system? (asking because the error mentions run_main, but your code snipped above says fn test.) Are you able to un-simplify the code / share a bit more?

nova sundial
#

gimme a sec, i'm going to try and reproduce the error in another file

#

im pretty sure that the error is unrelated to the other context in my program so i don't want to make it more confusing for you by including all of it

nova sundial
# obsidian comet Yeah, okay, that's interesting. I'm not sure how you could end up with that part...

here's a little reproduction that you can just copy and paste wherever, still produces the same error:

use bevy::prelude::*;

fn main() {
    App::new().add_systems(Update, test).run()
}

#[derive(Resource)]
struct SomeResource;

#[allow(unused_variables)]
fn test(query: Query<EntityMut>, some_resource: Res<SomeResource>) {}

error:

error[B0002]: Res<error_testing::SomeResource> in system error_testing::test conflicts with a previous ResMut<error_testing::SomeResource> access. Consider removing the duplicate access.
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Encountered a panic in system `bevy_app::main_schedule::Main::run_main`!
obsidian comet
#

Huh, I sort of glossed over the EntityMut part, as far as I know its access shouldn't conflict with a resource, and that error seems odd if that's all of the system params. Maybe that is a bug.

You might want to escalate to #ecs

#

Could be expected behavior, but someone over there is likely to know better. In any case, the error message seems pretty poor.

nova sundial
#

alr thanks

#

i think it does sort of makes sense that it could cause an error, but as you said, the error message makes it very confusing

austere parrot
#

Nice minimal code to reproduce the issue. Found these two ignored tests:

    #[test]
    #[ignore] // This should pass, but it currently fails due to limitations in our access model.
    fn mut_compatible_with_resource() {
        fn borrow_mut_system(_: Res<R>, _: Query<EntityMut>) {}

        assert_is_system(borrow_mut_system);
    }

    #[test]
    #[ignore] // This should pass, but it currently fails due to limitations in our access model.
    fn mut_compatible_with_resource_mut() {
        fn borrow_mut_system(_: ResMut<R>, _: Query<EntityMut>) {}

        assert_is_system(borrow_mut_system);
    }
#

Seems it's known to a Joseph at least.

wispy parcel