bevy/crates/bevy_ecs/src/world
MiniaczQ e312da8c52
Reduce runtime panics through SystemParam validation (#15276)
# Objective

The goal of this PR is to introduce `SystemParam` validation in order to
reduce runtime panics.

Fixes #15265

## Solution

`SystemParam` now has a new method `validate_param(...) -> bool`, which
takes immutable variants of `get_param` arguments. The returned value
indicates whether the parameter can be acquired from the world. If
parameters cannot be acquired for a system, it won't be executed,
similarly to run conditions. This reduces panics when using params like
`Res`, `ResMut`, etc. as well as allows for new, ergonomic params like
#15264 or #15302.

Param validation happens at the level of executors. All validation
happens directly before executing a system, in case of normal systems
they are skipped, in case of conditions they return false.

Warning about system skipping is primitive and subject to change in
subsequent PRs.

## Testing

Two executor tests check that all executors:
- skip systems which have invalid parameters:
  - piped systems get skipped together,
  - dependent systems still run correctly,
- skip systems with invalid run conditions:
  - system conditions have invalid parameters,
  - system set conditions have invalid parameters.
2024-09-23 16:54:21 +00:00
..
command_queue.rs Rename Add to Queue for methods with deferred semantics (#15234) 2024-09-17 00:17:49 +00:00
component_constants.rs Implement std::fmt::Debug for ecs::observer::Trigger (#14857) 2024-08-25 16:55:54 +00:00
deferred_world.rs Required Components (#14791) 2024-08-27 20:22:23 +00:00
entity_ref.rs Enable clippy::check-private-items so that missing_safety_doc will apply to private functions as well (#15161) 2024-09-18 15:28:41 +00:00
error.rs Replace all labels with interned labels (#7762) 2023-10-25 21:39:23 +00:00
identifier.rs Reduce runtime panics through SystemParam validation (#15276) 2024-09-23 16:54:21 +00:00
mod.rs Reduce runtime panics through SystemParam validation (#15276) 2024-09-23 16:54:21 +00:00
reflect.rs feat: Add World::get_reflect() and World::get_reflect_mut() (#14416) 2024-07-23 16:57:54 +00:00
spawn_batch.rs Track source location in change detection (#14034) 2024-07-30 12:02:38 +00:00
unsafe_world_cell.rs change return type of World::resource_ref to Ref (#15263) 2024-09-21 19:11:13 +00:00