Skip to content

Commit 6114347

Browse files
authored
Fix confusing comment in pbr example (#16996)
# Objective After a recent fix for a panic in the pbr example (#16976), the code contains the following comment: ```rust // This system relies on system parameters that are not available at start // Ignore parameter failures so that it will run when possible .add_systems(Update, environment_map_load_finish.never_param_warn()) ``` However, this explanation is incorrect. `EnvironmentMapLabel` is available at start. The real issue is that it is no longer available once it has been removed by `environment_map_load_finish`. ## Solution - Remove confusing/incorrect comment and `never_param_warn()`. - Make `Single<Entity, With<EnvironmentMapLabel>>` optional in `environment_map_load_finish`, and check that the entity has not yet been despawned. Since it is expected that an entity is no longer there once it has been despawned, it seems better to me to handle this case in `environment_map_load_finish`. ## Testing Ran `cargo run --example pbr`.
1 parent 0f2b2de commit 6114347

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

examples/3d/pbr.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ fn main() {
77
App::new()
88
.add_plugins(DefaultPlugins)
99
.add_systems(Startup, setup)
10-
// This system relies on system parameters that are not available at start
11-
// Ignore parameter failures so that it will run when possible
12-
.add_systems(Update, environment_map_load_finish.never_param_warn())
10+
.add_systems(Update, environment_map_load_finish)
1311
.run();
1412
}
1513

@@ -130,7 +128,7 @@ fn environment_map_load_finish(
130128
mut commands: Commands,
131129
asset_server: Res<AssetServer>,
132130
environment_map: Single<&EnvironmentMapLight>,
133-
label_entity: Single<Entity, With<EnvironmentMapLabel>>,
131+
label_entity: Option<Single<Entity, With<EnvironmentMapLabel>>>,
134132
) {
135133
if asset_server
136134
.load_state(&environment_map.diffuse_map)
@@ -139,7 +137,10 @@ fn environment_map_load_finish(
139137
.load_state(&environment_map.specular_map)
140138
.is_loaded()
141139
{
142-
commands.entity(*label_entity).despawn();
140+
// Do not attempt to remove `label_entity` if it has already been removed.
141+
if let Some(label_entity) = label_entity {
142+
commands.entity(*label_entity).despawn();
143+
}
143144
}
144145
}
145146

0 commit comments

Comments
 (0)