From e42d386625a235718d884cf7e9df1395736f1c88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Mockers?= Date: Wed, 2 Jul 2025 16:54:10 +0200 Subject: [PATCH] set required-features for example light_textures & clustered_decals (#19913) # Objective - Example `light_textures` exit if feature `pbr_light_textures` is not enabled. this is checked in code instead of using `required-features` - Same for `clustered_decals` and `par_clustered_decals` - Those examples are also using `eprintln` - Those examples are using `process:exit` to exit ## Solution - Use `required-features` - Use logs - Use `AppExit` --- Cargo.toml | 2 ++ examples/3d/clustered_decals.rs | 11 ++--------- examples/3d/light_textures.rs | 11 ++--------- 3 files changed, 6 insertions(+), 18 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 6bc73fbd2c..46b8238596 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4426,6 +4426,7 @@ wasm = true name = "clustered_decals" path = "examples/3d/clustered_decals.rs" doc-scrape-examples = true +required-features = ["pbr_clustered_decals"] [package.metadata.example.clustered_decals] name = "Clustered Decals" @@ -4437,6 +4438,7 @@ wasm = false name = "light_textures" path = "examples/3d/light_textures.rs" doc-scrape-examples = true +required-features = ["pbr_light_textures"] [package.metadata.example.light_textures] name = "Light Textures" diff --git a/examples/3d/clustered_decals.rs b/examples/3d/clustered_decals.rs index f8592d28c0..60a445b483 100644 --- a/examples/3d/clustered_decals.rs +++ b/examples/3d/clustered_decals.rs @@ -2,7 +2,6 @@ use std::f32::consts::{FRAC_PI_3, PI}; use std::fmt::{self, Formatter}; -use std::process; use bevy::{ color::palettes::css::{LIME, ORANGE_RED, SILVER}, @@ -163,16 +162,10 @@ fn setup( mut meshes: ResMut>, mut materials: ResMut>>, ) { - // Error out if the clustered decals feature isn't enabled - if !cfg!(feature = "pbr_clustered_decals") { - eprintln!("Bevy was compiled without clustered decal support. Run with `--features=pbr_clustered_decals` to enable."); - process::exit(1); - } - // Error out if clustered decals aren't supported on the current platform. if !decal::clustered::clustered_decals_are_usable(&render_device, &render_adapter) { - eprintln!("Clustered decals aren't usable on this platform."); - process::exit(1); + error!("Clustered decals aren't usable on this platform."); + commands.send_event(AppExit::error()); } spawn_cube(&mut commands, &mut meshes, &mut materials); diff --git a/examples/3d/light_textures.rs b/examples/3d/light_textures.rs index be221101b6..94ddd159f2 100644 --- a/examples/3d/light_textures.rs +++ b/examples/3d/light_textures.rs @@ -2,7 +2,6 @@ use std::f32::consts::{FRAC_PI_2, FRAC_PI_3, FRAC_PI_4, PI}; use std::fmt::{self, Formatter}; -use std::process; use bevy::{ color::palettes::css::{SILVER, YELLOW}, @@ -155,16 +154,10 @@ fn setup( mut meshes: ResMut>, mut materials: ResMut>, ) { - // Error out if the light textures feature isn't enabled - if !cfg!(feature = "pbr_light_textures") { - eprintln!("Bevy was compiled without light texture support. Run with `--features=pbr_light_textures` to enable."); - process::exit(1); - } - // Error out if clustered decals (and so light textures) aren't supported on the current platform. if !decal::clustered::clustered_decals_are_usable(&render_device, &render_adapter) { - eprintln!("Light textures aren't usable on this platform."); - process::exit(1); + error!("Light textures aren't usable on this platform."); + commands.send_event(AppExit::error()); } spawn_cubes(&mut commands, &mut meshes, &mut materials);