Skip to content

Commit 6fbd585

Browse files
pablo-luamockersf
andauthored
Fix gizmos app new panic (#11420)
# Objective After the Gizmos changes, `App::init_gizmos_group` turned into a important function that for sure mustn't panic. The problem is: the actual implementation causes a panic if somehow the code is runned before `GizmoPlugin` was added to the App - The error occurs here for example: ```rust fn main() { App::new() .init_gizmo_group::<MyGizmoConfig>() .add_plugins(DefaultPlugins) .run(); } #[derive(Default, Reflect, GizmoConfigGroup)] struct MyGizmoConfig; ``` ![image](https://github.com/bevyengine/bevy/assets/126117294/35e75608-0946-4320-8035-00a82562e37e) ## Solution - Instead of panicking when getting `GizmoConfigStore`, insert the store in `App::init_gizmos_group` if needed --- ## Changelog ### Changed - Changed App::init_gizmos_group to insert the resource if it don't exist ### Removed - Removed explicit init of `GizmoConfigStore` --------- Co-authored-by: François <[email protected]>
1 parent cd2cdb4 commit 6fbd585

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

crates/bevy_gizmos/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ impl Plugin for GizmoPlugin {
103103
.init_asset::<LineGizmo>()
104104
.add_plugins(RenderAssetPlugin::<LineGizmo>::default())
105105
.init_resource::<LineGizmoHandles>()
106-
.init_resource::<GizmoConfigStore>()
106+
// We insert the Resource GizmoConfigStore into the world implicitly here if it does not exist.
107107
.init_gizmo_group::<DefaultGizmoConfigGroup>()
108108
.add_plugins(AabbGizmoPlugin);
109109

@@ -158,7 +158,7 @@ impl AppGizmoBuilder for App {
158158
.add_systems(Last, update_gizmo_meshes::<T>);
159159

160160
self.world
161-
.resource_mut::<GizmoConfigStore>()
161+
.get_resource_or_insert_with::<GizmoConfigStore>(Default::default)
162162
.register::<T>();
163163

164164
let Ok(render_app) = self.get_sub_app_mut(RenderApp) else {

0 commit comments

Comments
 (0)