From e63b69514723c499db86d9c74c510e74c8192d99 Mon Sep 17 00:00:00 2001 From: Sergi Puig Date: Mon, 25 Mar 2024 21:07:05 +0100 Subject: [PATCH 1/4] Fix Gizmo causing panic when disabling a plugin dependency --- crates/bevy_gizmos/src/lib.rs | 18 +++++++++-- crates/bevy_gizmos/src/pipeline_2d.rs | 7 ++++- crates/bevy_gizmos/src/pipeline_3d.rs | 4 ++- crates/bevy_internal/src/default_plugins.rs | 35 ++++----------------- 4 files changed, 31 insertions(+), 33 deletions(-) diff --git a/crates/bevy_gizmos/src/lib.rs b/crates/bevy_gizmos/src/lib.rs index 181408d222108..0e758e2414703 100755 --- a/crates/bevy_gizmos/src/lib.rs +++ b/crates/bevy_gizmos/src/lib.rs @@ -94,6 +94,11 @@ use std::{any::TypeId, mem}; const LINE_SHADER_HANDLE: Handle = Handle::weak_from_u128(7414812689238026784); /// A [`Plugin`] that provides an immediate mode drawing api for visual debugging. +/// +/// Requires to be loaded after [PbrPlugin] or [SpritePlugin]. +/// +/// [PbrPlugin]: bevy_pbr::PbrPlugin +/// [SpritePlugin]: bevy_sprite::SpritePlugin pub struct GizmoPlugin; impl Plugin for GizmoPlugin { @@ -128,10 +133,19 @@ impl Plugin for GizmoPlugin { render_app.add_systems(ExtractSchedule, extract_gizmo_data); + #[cfg(feature = "bevy_sprite")] - app.add_plugins(pipeline_2d::LineGizmo2dPlugin); + if app.is_plugin_added::() { + app.add_plugins(pipeline_2d::LineGizmo2dPlugin); + } else { + bevy_utils::tracing::warn!("bevy_sprite feature is enabled but bevy_sprite::SpritePlugin was not detected. Are you sure you loaded GizmoPlugin after SpritePlugin?") + } #[cfg(feature = "bevy_pbr")] - app.add_plugins(pipeline_3d::LineGizmo3dPlugin); + if app.is_plugin_added::() { + app.add_plugins(pipeline_3d::LineGizmo3dPlugin); + } else { + bevy_utils::tracing::warn!("bevy_pbr feature is enabled but bevy_pbr::PbrPlugin was not detected. Are you sure you loaded GizmoPlugin after PbrPlugin?") + } } fn finish(&self, app: &mut bevy_app::App) { diff --git a/crates/bevy_gizmos/src/pipeline_2d.rs b/crates/bevy_gizmos/src/pipeline_2d.rs index f55453fa67035..cdc06dc37c79d 100644 --- a/crates/bevy_gizmos/src/pipeline_2d.rs +++ b/crates/bevy_gizmos/src/pipeline_2d.rs @@ -36,7 +36,12 @@ impl Plugin for LineGizmo2dPlugin { .init_resource::>() .configure_sets( Render, - GizmoRenderSystem::QueueLineGizmos2d.in_set(RenderSet::Queue), + GizmoRenderSystem::QueueLineGizmos2d + .in_set(RenderSet::Queue) + .ambiguous_with(bevy_sprite::queue_sprites) + .ambiguous_with( + bevy_sprite::queue_material2d_meshes::, + ), ) .add_systems( Render, diff --git a/crates/bevy_gizmos/src/pipeline_3d.rs b/crates/bevy_gizmos/src/pipeline_3d.rs index bd5064e39d789..214c14bf91643 100644 --- a/crates/bevy_gizmos/src/pipeline_3d.rs +++ b/crates/bevy_gizmos/src/pipeline_3d.rs @@ -38,7 +38,9 @@ impl Plugin for LineGizmo3dPlugin { .init_resource::>() .configure_sets( Render, - GizmoRenderSystem::QueueLineGizmos3d.in_set(RenderSet::Queue), + GizmoRenderSystem::QueueLineGizmos3d + .in_set(RenderSet::Queue) + .ambiguous_with(bevy_pbr::queue_material_meshes::), ) .add_systems( Render, diff --git a/crates/bevy_internal/src/default_plugins.rs b/crates/bevy_internal/src/default_plugins.rs index dcea35be338e3..5c59f698482d7 100644 --- a/crates/bevy_internal/src/default_plugins.rs +++ b/crates/bevy_internal/src/default_plugins.rs @@ -153,35 +153,12 @@ impl Plugin for IgnoreAmbiguitiesPlugin { fn build(&self, app: &mut bevy_app::App) { // bevy_ui owns the Transform and cannot be animated #[cfg(all(feature = "bevy_animation", feature = "bevy_ui"))] - app.ignore_ambiguity( - bevy_app::PostUpdate, - bevy_animation::advance_animations, - bevy_ui::ui_layout_system, - ); - - #[cfg(feature = "bevy_render")] - if let Ok(render_app) = app.get_sub_app_mut(bevy_render::RenderApp) { - #[cfg(all(feature = "bevy_gizmos", feature = "bevy_sprite"))] - { - render_app.ignore_ambiguity( - bevy_render::Render, - bevy_gizmos::GizmoRenderSystem::QueueLineGizmos2d, - bevy_sprite::queue_sprites, - ); - render_app.ignore_ambiguity( - bevy_render::Render, - bevy_gizmos::GizmoRenderSystem::QueueLineGizmos2d, - bevy_sprite::queue_material2d_meshes::, - ); - } - #[cfg(all(feature = "bevy_gizmos", feature = "bevy_pbr"))] - { - render_app.ignore_ambiguity( - bevy_render::Render, - bevy_gizmos::GizmoRenderSystem::QueueLineGizmos3d, - bevy_pbr::queue_material_meshes::, - ); - } + if app.is_plugin_added::() && app.is_plugin_added::() { + app.ignore_ambiguity( + bevy_app::PostUpdate, + bevy_animation::advance_animations, + bevy_ui::ui_layout_system, + ); } } } From 3f8d72fe6c515c0fd57b50c3bc78c24cb0b8ec2a Mon Sep 17 00:00:00 2001 From: Sergi Puig Date: Fri, 29 Mar 2024 13:04:12 +0100 Subject: [PATCH 2/4] Fix docs --- crates/bevy_gizmos/src/lib.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/crates/bevy_gizmos/src/lib.rs b/crates/bevy_gizmos/src/lib.rs index 0e758e2414703..7b4fd962f3735 100755 --- a/crates/bevy_gizmos/src/lib.rs +++ b/crates/bevy_gizmos/src/lib.rs @@ -95,10 +95,7 @@ const LINE_SHADER_HANDLE: Handle = Handle::weak_from_u128(74148126892380 /// A [`Plugin`] that provides an immediate mode drawing api for visual debugging. /// -/// Requires to be loaded after [PbrPlugin] or [SpritePlugin]. -/// -/// [PbrPlugin]: bevy_pbr::PbrPlugin -/// [SpritePlugin]: bevy_sprite::SpritePlugin +/// Requires to be loaded after [`PbrPlugin`](bevy_pbr::PbrPlugin) or [`SpritePlugin`](bevy_sprite::SpritePlugin). pub struct GizmoPlugin; impl Plugin for GizmoPlugin { From 09650d081692caaf18744e7c5a8aec714696154d Mon Sep 17 00:00:00 2001 From: Sergi Puig Date: Fri, 29 Mar 2024 13:08:11 +0100 Subject: [PATCH 3/4] Linting --- crates/bevy_gizmos/src/lib.rs | 1 - crates/bevy_internal/src/default_plugins.rs | 4 +++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/bevy_gizmos/src/lib.rs b/crates/bevy_gizmos/src/lib.rs index 7b4fd962f3735..294b9e869040d 100755 --- a/crates/bevy_gizmos/src/lib.rs +++ b/crates/bevy_gizmos/src/lib.rs @@ -130,7 +130,6 @@ impl Plugin for GizmoPlugin { render_app.add_systems(ExtractSchedule, extract_gizmo_data); - #[cfg(feature = "bevy_sprite")] if app.is_plugin_added::() { app.add_plugins(pipeline_2d::LineGizmo2dPlugin); diff --git a/crates/bevy_internal/src/default_plugins.rs b/crates/bevy_internal/src/default_plugins.rs index 5c59f698482d7..9c8838470eb5b 100644 --- a/crates/bevy_internal/src/default_plugins.rs +++ b/crates/bevy_internal/src/default_plugins.rs @@ -153,7 +153,9 @@ impl Plugin for IgnoreAmbiguitiesPlugin { fn build(&self, app: &mut bevy_app::App) { // bevy_ui owns the Transform and cannot be animated #[cfg(all(feature = "bevy_animation", feature = "bevy_ui"))] - if app.is_plugin_added::() && app.is_plugin_added::() { + if app.is_plugin_added::() + && app.is_plugin_added::() + { app.ignore_ambiguity( bevy_app::PostUpdate, bevy_animation::advance_animations, From 6879c695c919b1b536e2ec764ec66074deaee8d6 Mon Sep 17 00:00:00 2001 From: Sergi Puig Date: Fri, 29 Mar 2024 13:20:56 +0100 Subject: [PATCH 4/4] Fix CI --- crates/bevy_gizmos/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/bevy_gizmos/src/lib.rs b/crates/bevy_gizmos/src/lib.rs index 294b9e869040d..325f741076b70 100755 --- a/crates/bevy_gizmos/src/lib.rs +++ b/crates/bevy_gizmos/src/lib.rs @@ -134,13 +134,13 @@ impl Plugin for GizmoPlugin { if app.is_plugin_added::() { app.add_plugins(pipeline_2d::LineGizmo2dPlugin); } else { - bevy_utils::tracing::warn!("bevy_sprite feature is enabled but bevy_sprite::SpritePlugin was not detected. Are you sure you loaded GizmoPlugin after SpritePlugin?") + bevy_utils::tracing::warn!("bevy_sprite feature is enabled but bevy_sprite::SpritePlugin was not detected. Are you sure you loaded GizmoPlugin after SpritePlugin?"); } #[cfg(feature = "bevy_pbr")] if app.is_plugin_added::() { app.add_plugins(pipeline_3d::LineGizmo3dPlugin); } else { - bevy_utils::tracing::warn!("bevy_pbr feature is enabled but bevy_pbr::PbrPlugin was not detected. Are you sure you loaded GizmoPlugin after PbrPlugin?") + bevy_utils::tracing::warn!("bevy_pbr feature is enabled but bevy_pbr::PbrPlugin was not detected. Are you sure you loaded GizmoPlugin after PbrPlugin?"); } }