-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Prevent conflicting system resource parameters #864
Conversation
This comment has been minimized.
This comment has been minimized.
I think it can be useful to have multiple copies of the same #[derive(SystemParam)]
struct Outer<'a> {
inner: Inner<'a>,
foo: Res<'a, Foo>,
}
impl<'a> Outer<'a> {
pub fn use_inner(&self) { self.inner.use_foo() }
}
mod inner {
#[derive(SystemParam)]
pub struct Inner<'a> {
foo: Res<'a, Foo>,
}
impl<'a> Inner<'a> {
pub fn use_foo(&self) {}
}
} |
@bonsairobo do you have a fuller example? Inner is repeating the fields thar Outer already has access to. |
I just mean that |
Makes sense ^^ it’s a small change to make the |
4227d83
to
613cbd5
Compare
@memoryruins Thanks for hearing me out. I only spoke up because I've run into this issue before with specs, and I found it annoying that it wouldn't let me read the same thing twice from the same system. |
Very good call! Thanks 😄
Yeah I think this is a good call. Right now its fine to just ignore local resource access in the scheduler because there are only two ways to access Local resources:
If we ever add the ability to access arbitrary Local resources in query systems, then we will need to take that in to account. |
Currently, a system is allowed to have multiple resource parameters to the same resource type. No current checks prevent multiple mutable borrows aliasing the same resource. Surprisingly, this applies to multiple local resources too in a slightly different way.
examples
This PR adds access checks to the
SystemParam::init
implementation ofRes
,ResMut
,ChangedRes
, andLocal
.Something I'm unsure about is how I split out the local type accesses. Without tracking local type access independently, a
Local<Foo>
andRes<Foo>
would incorrectly lead to a conflict. Is that change appropriate or is tracking local resources needed for parallel schedulers checks?