From 740d1cc9ffc1a9f9c31b8fbb0f3a79ff81adf021 Mon Sep 17 00:00:00 2001 From: MiniaczQ Date: Mon, 23 Sep 2024 22:25:49 +0200 Subject: [PATCH] Fix system param warnings on systems that cannot run anyways (#15397) # Objective Fix "system skipped" warnings when validation fails on systems that wouldn't run because of run conditions. ## Solution > I think the error is from a system defined as: > > ```rust > no_gpu_preprocessing::batch_and_prepare_sorted_render_phase:: > .run_if(resource_exists::>), > ``` > > So the `run_if` was preventing the panics. Maybe we need to skip validation if `!system_conditions_met`, or at least silence the warning in that case. *By @chescock in https://discord.com/channels/691052431525675048/692572690833473578/1287865365312831562* Validation of system is skipped if the system was already skipped by run conditions. ## Testing Ran alien addict example, no more warnings. --- .../src/schedule/executor/multi_threaded.rs | 22 +++++++++---------- .../bevy_ecs/src/schedule/executor/simple.rs | 12 +++++----- .../src/schedule/executor/single_threaded.rs | 12 +++++----- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/crates/bevy_ecs/src/schedule/executor/multi_threaded.rs b/crates/bevy_ecs/src/schedule/executor/multi_threaded.rs index 168d3739e2..92f71362ea 100644 --- a/crates/bevy_ecs/src/schedule/executor/multi_threaded.rs +++ b/crates/bevy_ecs/src/schedule/executor/multi_threaded.rs @@ -568,19 +568,19 @@ impl ExecutorState { should_run &= system_conditions_met; - // SAFETY: - // - The caller ensures that `world` has permission to read any data - // required by the system. - // - `update_archetype_component_access` has been called for system. - let valid_params = unsafe { system.validate_param_unsafe(world) }; - - if !valid_params { - warn_system_skipped!("System", system.name()); - self.skipped_systems.insert(system_index); + if should_run { + // SAFETY: + // - The caller ensures that `world` has permission to read any data + // required by the system. + // - `update_archetype_component_access` has been called for system. + let valid_params = unsafe { system.validate_param_unsafe(world) }; + if !valid_params { + warn_system_skipped!("System", system.name()); + self.skipped_systems.insert(system_index); + } + should_run &= valid_params; } - should_run &= valid_params; - should_run } diff --git a/crates/bevy_ecs/src/schedule/executor/simple.rs b/crates/bevy_ecs/src/schedule/executor/simple.rs index 12e257624b..3a7dd05397 100644 --- a/crates/bevy_ecs/src/schedule/executor/simple.rs +++ b/crates/bevy_ecs/src/schedule/executor/simple.rs @@ -81,14 +81,14 @@ impl SystemExecutor for SimpleExecutor { should_run &= system_conditions_met; let system = &mut schedule.systems[system_index]; - let valid_params = system.validate_param(world); - - if !valid_params { - warn_system_skipped!("System", system.name()); + if should_run { + let valid_params = system.validate_param(world); + if !valid_params { + warn_system_skipped!("System", system.name()); + } + should_run &= valid_params; } - should_run &= valid_params; - #[cfg(feature = "trace")] should_run_span.exit(); diff --git a/crates/bevy_ecs/src/schedule/executor/single_threaded.rs b/crates/bevy_ecs/src/schedule/executor/single_threaded.rs index 5cc52003a0..3ae907c4f5 100644 --- a/crates/bevy_ecs/src/schedule/executor/single_threaded.rs +++ b/crates/bevy_ecs/src/schedule/executor/single_threaded.rs @@ -87,14 +87,14 @@ impl SystemExecutor for SingleThreadedExecutor { should_run &= system_conditions_met; let system = &mut schedule.systems[system_index]; - let valid_params = system.validate_param(world); - - if !valid_params { - warn_system_skipped!("System", system.name()); + if should_run { + let valid_params = system.validate_param(world); + if !valid_params { + warn_system_skipped!("System", system.name()); + } + should_run &= valid_params; } - should_run &= valid_params; - #[cfg(feature = "trace")] should_run_span.exit();