bevy/crates
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
..
bevy_a11y Update accesskit and accesskit_winit requirements (#18285) 2025-03-25 22:44:01 +01:00
bevy_animation Reduce dependencies on bevy_render by preferring bevy_mesh imports (#18437) 2025-03-25 22:45:39 +01:00
bevy_app Release 0.16.0-rc.1 2025-03-18 21:48:22 +01:00
bevy_asset Don't panic on temporary files in file watcher (#18462) 2025-03-25 22:45:41 +01:00
bevy_audio Release 0.16.0-rc.1 2025-03-18 21:48:22 +01:00
bevy_color Release 0.16.0-rc.1 2025-03-18 21:48:22 +01:00
bevy_core_pipeline Record bloom render commands in parallel (#18330) 2025-03-25 22:44:01 +01:00
bevy_derive Release 0.16.0-rc.1 2025-03-18 21:48:22 +01:00
bevy_dev_tools Release 0.16.0-rc.1 2025-03-18 21:48:22 +01:00
bevy_diagnostic Release 0.16.0-rc.1 2025-03-18 21:48:22 +01:00
bevy_dylib Switch from OnceCell to LazyLock in bevy_tasks (#18506) 2025-03-25 22:41:01 +01:00
bevy_ecs Fix run_system for adapter systems wrapping exclusive systems (#18406) 2025-03-26 19:06:51 +01:00
bevy_encase_derive Release 0.16.0-rc.1 2025-03-18 21:48:22 +01:00
bevy_gilrs Release 0.16.0-rc.1 2025-03-18 21:48:22 +01:00
bevy_gizmos Replace ValidationOutcome with Result (#18541) 2025-03-26 09:01:42 +01:00
bevy_gltf Reduce dependencies on bevy_render by preferring bevy_mesh imports (#18437) 2025-03-25 22:45:39 +01:00
bevy_image Ensure dds enables bevy_core_pipeline/dds in bevy_anti_aliasing (#18484) 2025-03-24 00:11:37 +01:00
bevy_input Release 0.16.0-rc.1 2025-03-18 21:48:22 +01:00
bevy_input_focus Release 0.16.0-rc.1 2025-03-18 21:48:22 +01:00
bevy_internal Fix bevy_math/transform/input Improper Inclusion (#18526) 2025-03-25 22:59:04 +01:00
bevy_log Release 0.16.0-rc.1 2025-03-18 21:48:22 +01:00
bevy_macro_utils Release 0.16.0-rc.1 2025-03-18 21:48:22 +01:00
bevy_math Add no_std compatible ceil method (#18498) 2025-03-25 22:59:04 +01:00
bevy_mesh Reduce dependencies on bevy_render by preferring bevy_mesh imports (#18437) 2025-03-25 22:45:39 +01:00
bevy_mikktspace Release 0.16.0-rc.1 2025-03-18 21:48:22 +01:00
bevy_pbr Move non-generic parts of the PrepassPipeline to internal field (#18322) 2025-03-25 22:59:04 +01:00
bevy_picking Make RayMap map public (#18544) 2025-03-25 22:59:05 +01:00
bevy_platform_support Address lints in bevy_platform_support (#18477) 2025-03-24 00:09:30 +01:00
bevy_ptr Release 0.16.0-rc.1 2025-03-18 21:48:22 +01:00
bevy_reflect Update bincode to 2.0 (#18396) 2025-03-25 22:44:01 +01:00
bevy_remote fix error and lints when building for wasm32 (#18500) 2025-03-24 00:14:22 +01:00
bevy_render Replace ValidationOutcome with Result (#18541) 2025-03-26 09:01:42 +01:00
bevy_scene Update bincode to 2.0 (#18396) 2025-03-25 22:44:01 +01:00
bevy_sprite don't flip sprites twice (#18535) 2025-03-25 22:59:04 +01:00
bevy_state Release 0.16.0-rc.1 2025-03-18 21:48:22 +01:00
bevy_tasks Switch from OnceCell to LazyLock in bevy_tasks (#18506) 2025-03-25 22:41:01 +01:00
bevy_text ExtractedSprites slice buffer (#17041) 2025-03-25 22:43:58 +01:00
bevy_time Fix clippy::unnecessary-literal-unwrap in bevy_time (#18485) 2025-03-24 00:14:22 +01:00
bevy_transform Release 0.16.0-rc.1 2025-03-18 21:48:22 +01:00
bevy_ui Update accesskit and accesskit_winit requirements (#18285) 2025-03-25 22:44:01 +01:00
bevy_utils Release 0.16.0-rc.1 2025-03-18 21:48:22 +01:00
bevy_window Replace VisitEntities with MapEntities (#18432) 2025-03-24 00:09:29 +01:00
bevy_winit Fix UpdateMode::Reactive behavior on Windows (#18493) 2025-03-25 23:01:22 +01:00