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`
This commit is contained in:
François Mockers 2025-07-02 16:54:10 +02:00 committed by GitHub
parent 607f9f24d3
commit e42d386625
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 6 additions and 18 deletions

View File

@ -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"

View File

@ -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<Assets<Mesh>>,
mut materials: ResMut<Assets<ExtendedMaterial<StandardMaterial, CustomDecalExtension>>>,
) {
// 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);

View File

@ -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<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
// 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);