Coder Social home page Coder Social logo

Comments (2)

iiYese avatar iiYese commented on September 7, 2024

The clock has to be rewound back to 0.9 for it to crash as it should. But you don't get an access panic you get an error from the stdlib which is only in debug builds.

use bevy::prelude::*;

#[derive(Deref, DerefMut, Component)]
struct Foo(u32);

fn setup(mut cmds: Commands) {
    cmds.spawn(Foo(0));
}

fn update(mut query: Query<AnyOf<(&mut Foo, &mut Foo)>>) {
    let Ok((Some(mut a), Some(mut b))) = query.get_single_mut() else {
        return;
    };
    **a += 1;
    **b += 1;
    println!("did a ub {} {}", **a, **b);
}

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_startup_system(setup)
        .add_system(update)
        .run();
}
did a ub 2 2
thread 'main' panicked at library/core/src/panicking.rs:220:5:
unsafe precondition(s) violated: slice::from_raw_parts requires the pointer to be aligned and non-null, and the total size of the slice not to exceed `isize::MAX`

from bevy.

Gingeh avatar Gingeh commented on September 7, 2024

I was able to get it working(?) after some tinkering around with AnyOf's update_component_access impl.

diff --git a/crates/bevy_ecs/src/query/fetch.rs b/crates/bevy_ecs/src/query/fetch.rs
index 2ebf95cde..847653ab1 100644
--- a/crates/bevy_ecs/src/query/fetch.rs
+++ b/crates/bevy_ecs/src/query/fetch.rs
@@ -1872,10 +1872,12 @@ macro_rules! impl_anytuple_fetch {
                         $name::update_component_access($name, &mut intermediate);
                         _new_access.append_or(&intermediate);
                         _new_access.extend_access(&intermediate);
+                        _access.extend_access(&intermediate); // add accesses for remaining items to check against
                     } else {
                         $name::update_component_access($name, &mut _new_access);
                         _new_access.required = _access.required.clone();
                         _not_first = true;
+                        _access.extend_access(&_new_access); // add accesses for remaining items to check against
                     }
                 )*
 
diff --git a/crates/bevy_ecs/src/system/mod.rs b/crates/bevy_ecs/src/system/mod.rs
index b41255194..075e04692 100644
--- a/crates/bevy_ecs/src/system/mod.rs
+++ b/crates/bevy_ecs/src/system/mod.rs
@@ -564,6 +564,14 @@ mod tests {
         run_system(&mut world, sys);
     }
 
+    #[test]
+    #[should_panic = "&mut bevy_ecs::system::tests::A conflicts with a previous access in this query."]
+    fn any_of_with_conflicting() {
+        fn sys(_: Query<AnyOf<(&mut A, &mut A)>>) {}
+        let mut world = World::default();
+        run_system(&mut world, sys);
+    }
+
     #[test]
     fn any_of_has_filter_with_when_both_have_it() {
         fn sys(_: Query<(AnyOf<(&A, &A)>, &mut B)>, _: Query<&mut B, Without<A>>) {}

I have a very limited understanding of how this all works, so take this with a hefty grain of salt.

from bevy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.