
# 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.
422 B
422 B
title | pull_requests | |
---|---|---|
Exclusive systems may not be used as observers |
|
Exclusive systems may no longer be used as observers.
This was never sound, as the engine keeps references alive during observer invocation that would be invalidated by &mut World
access, but was accidentally allowed.
Instead of &mut World
, use either DeferredWorld
if you do not need structural changes, or Commands
if you do.