[Bugfix] add_stage now checks Stage existence #1346
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What's the bug?
add_stage
never checked whether a givenStage
-name already exists (which extends towith_stage()
)bevy/crates/bevy_ecs/src/schedule/mod.rs
Lines 59 to 63 in cc9ed52
instead simply
Stage
inSchedule.stages
(effectively removing all systems/schedulers/... attached to that old Stage)Schedule.stage_order
, while not removing the already existing one, creating a duplicateHow is it fixed?
This has been fixed using the same method the other two functions
add_stage_after
andadd_stage_before
use:This also raises the question:
Stage
-name is already taken, or should some sort of Error-flow be implemented to allow handling it?Why does it matter?
Since this bug effectively changed system-execution, it could have caused some interesting and hard to debug problems.
Especially later on, when other Stages are added in relation to this one.
add_stage
is supposed to place a Stage at the end of execution-order at the time of calling (Vec::push()
). Thus anything added via e.g.add_stage_before(this_broken_stage)
would be expected to execute as e.g. second-last. Howeveradd_stage_before
determines positioning via:This would return the index of the duplicate in
Schedule.stage_order
at the old position, earlier in the execution-order.