Fixes panic when using Option<Gizmos>#22812
Open
kfc35 wants to merge 1 commit intobevyengine:mainfrom
Open
Conversation
kfc35
commented
Feb 5, 2026
| storage.list_colors.append(&mut self.list_colors); | ||
| storage.strip_positions.append(&mut self.strip_positions); | ||
| storage.strip_colors.append(&mut self.strip_colors); | ||
| if let Some(mut storage) = world.get_resource_mut::<GizmoStorage<Config, Clear>>() { |
Contributor
Author
There was a problem hiding this comment.
Note to self that I need to also make this change to queue() #22800
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Objective
SystemParam(especially gizmos) #14949Option<Gizmos>causes a panic when the config group backingGizmoshas not been initialized. The desired behavior is to have it beNoneinstead of course.Solution
Gizmosis a non#[derive]'dSystemParamthat requires itsGizmoConfigGroupto have an entry inGizmoConfigStoreGizmoStorages to be inserted as resources.In order to support a non-panicking
Option<Gizmos>SystemParamin a non-intrusive way for users when the Gizmo Config Group has not been set up intentionally, this PR:GizmoConfigStorevalidate_parammethod ofGizmosto return a skippable error in the event that it could not find its own config in theGizmoConfigStoreapplymethod ofGizmoBufferto only apply changes if theGizmoStoragefor the config group exists.Testing
I modified the 2d gizmos example (
cargo run --example 2d_gizmos) by:// .init_gizmo_group::<MyRoundGizmos>()Option<Gizmos>andOption<Gizmos<MyRoundGizmos>>) for the twoGizmossystem parameters indraw_example_collectionand requiringmy_gizmos_option.is_some()before using an unwrappedmy_gizmosto draw things.GizmoConfigStoremethodtry_config_mutwhen trying to get the config forMyRoundGizmos, and only proceeding to change its settings ifmy_config_option.is_some()There are no crashes. Default Gizmos continue to be drawn, and
MyRoundGizmosare not drawn. Changing the settings still works for default gizmos, and has no effect if they were to be applied toMyRoundGizmos. There seems to be no deterioration in performance for the example.