bevy/crates/bevy_ecs/src/schedule
Chris Russell 4bc4f93f5b Fix run_system for adapter systems wrapping exclusive systems (#18406)
# Objective

Fix panic in `run_system` when running an exclusive system wrapped in a
`PipeSystem` or `AdapterSystem`.

#18076 introduced a `System::run_without_applying_deferred` method. It
normally calls `System::run_unsafe`, but
`ExclusiveFunctionSystem::run_unsafe` panics, so it was overridden for
that type. Unfortunately, `PipeSystem::run_without_applying_deferred`
still calls `PipeSystem::run_unsafe`, which can then call
`ExclusiveFunctionSystem::run_unsafe` and panic.

## Solution

Make `ExclusiveFunctionSystem::run_unsafe` work instead of panicking.
Clarify the safety requirements that make this sound.

The alternative is to override `run_without_applying_deferred` in
`PipeSystem`, `CombinatorSystem`, `AdapterSystem`,
`InfallibleSystemWrapper`, and `InfallibleObserverWrapper`. That seems
like a lot of extra code just to preserve a confusing special case!

Remove some implementations of `System::run` that are no longer
necessary with this change. This slightly changes the behavior of
`PipeSystem` and `CombinatorSystem`: Currently `run` will call
`apply_deferred` on the first system before running the second, but
after this change it will only call it after *both* systems have run.
The new behavior is consistent with `run_unsafe` and
`run_without_applying_deferred`, and restores the behavior prior to
#11823.

The panic was originally necessary because [`run_unsafe` took
`&World`](https://github.com/bevyengine/bevy/pull/6083/files#diff-708dfc60ec5eef432b20a6f471357a7ea9bfb254dc2f918d5ed4a66deb0e85baR90).
Now that it takes `UnsafeWorldCell`, it is possible to make it work. See
also Cart's concerns at
https://github.com/bevyengine/bevy/pull/4166#discussion_r979140356,
although those also predate `UnsafeWorldCell`.

And see #6698 for a previous bug caused by this panic.
2025-03-26 19:06:51 +01:00
..
executor Fix run_system for adapter systems wrapping exclusive systems (#18406) 2025-03-26 19:06:51 +01:00
graph Generic system config (#17962) 2025-03-12 00:12:30 +00:00
auto_insert_apply_deferred.rs Bubble sync points if ignore_deferred, do not ignore if target system is exclusive (#17880) 2025-02-26 20:39:23 +00:00
condition.rs Generic system config (#17962) 2025-03-12 00:12:30 +00:00
config.rs Generic system config (#17962) 2025-03-12 00:12:30 +00:00
mod.rs Upgrade to Rust Edition 2024 (#17967) 2025-02-24 03:54:47 +00:00
pass.rs Schedule build pass (#11094) 2025-02-05 23:14:05 +00:00
schedule.rs Unify and simplify command and system error handling (#18351) 2025-03-18 21:18:06 +01:00
set.rs Harden proc macro path resolution and add integration tests. (#17330) 2025-02-09 19:45:45 +00:00
stepping.rs Add print_stdout and print_stderr lints (#17446) (#18233) 2025-03-11 19:35:48 +00:00