-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Prevent exclusive systems from being used as observers #19033
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 exclusive systems from being used as observers #19033
Conversation
Is there any chance this can be backported to 0.16.1? Given it's a soundness issue I was thinking |
I realized this might require a migration guide if anyone is doing this today... but then I thought it would be even better to put the guide in the error message so that anyone trying this in the future also gets guidance. So I did that instead! |
having it on the error is very smart, but i don't think it removes the need of the migration guide |
Agreed, we should tackle this in follow-up at some point. |
) # Objective Prevent using exclusive systems as observers. Allowing them is unsound, because observers are only expected to have `DeferredWorld` access, and the observer infrastructure will keep pointers that are invalidated by the creation of `&mut World`. See https://github.com/bevyengine/bevy/actions/runs/14778342801/job/41491517847?pr=19011 for a MIRI failure in a recent PR caused by an exclusive system being used as an observer in a test. ## Solution Have `Observer::new` panic if `System::is_exclusive()` is true. Document that method, and methods that call it, as panicking. (It should be possible to express this in the type system so that the calls won't even compile, but I did not want to attempt that.) ## Testing Added a unit test that calls `World::add_observer` with an exclusive system.
Objective
Prevent using exclusive systems as observers. Allowing them is unsound, because observers are only expected to have
DeferredWorld
access, and the observer infrastructure will keep pointers that are invalidated by the creation of&mut World
.See https://github.com/bevyengine/bevy/actions/runs/14778342801/job/41491517847?pr=19011 for a MIRI failure in a recent PR caused by an exclusive system being used as an observer in a test.
Solution
Have
Observer::new
panic ifSystem::is_exclusive()
is true. Document that method, and methods that call it, as panicking.(It should be possible to express this in the type system so that the calls won't even compile, but I did not want to attempt that.)
Testing
Added a unit test that calls
World::add_observer
with an exclusive system.