-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Reduce runtime panics through SystemParam
validation
#15276
Conversation
The opinions of the SME-ECS (@JoJoJet @maniwani @james7132 and myself) and frankly the rest of the ECS community are very positive on the broad direction of this work, so I'm marking it as |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very pleased about how non-intrusive this is!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made some comments on the safety for the single_threaded executor and I believe the simple executor has the same issues. It's late here so I might be missing something obvious, but I don't see update_archetype_component_access
being called for the conditions for either of those two executors.
crates/bevy_ecs/src/system/system.rs
Outdated
/// # Safety | ||
/// | ||
/// - The caller must ensure that `world` has permission to read any world data | ||
/// registered in [`Self::archetype_component_access`]. There must be no conflicting |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this mention update_archetype_component_access
while the other validate_param
s mention init_state
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was copy-paste from get_param
/run
methods, this means that they are also inconsistent with each other.
Agreed it should refer to update_archetype_component_access
and some reference to new_archetype
instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed, let me know if that's sufficient.
If not I'm afraid we'll need a follow up PR since Alice wants this merged in the next train
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it's good enough now, I'm ok with merging it and maybe improve the wording in a follow up PR
Thank you to everyone involved with the authoring or reviewing of this PR! This work is relatively important and needs release notes! Head over to bevyengine/bevy-website#1691 if you'd like to help out. |
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 methodvalidate_param(...) -> bool
, which takes immutable variants ofget_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 likeRes
,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: