Skip to content

Commit 7398d33

Browse files
authored
Panic on failure in scene example (bevyengine#17812)
# Objective Fixes bevyengine#17810 Y'all picked the option I already implemented, yay. ## Solution Add a system that panics if the load state of an asset is `Failed`. ## Testing `cargo run --example scene` - Tested with valid scene file - Introduced a syntax error in the scene file - Deleted the scene file
1 parent 94deca8 commit 7398d33

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

examples/scene/scene.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
//! won't work on WASM because WASM typically doesn't have direct filesystem access.
2525
//!
2626
27-
use bevy::{prelude::*, tasks::IoTaskPool};
27+
use bevy::{asset::LoadState, prelude::*, tasks::IoTaskPool};
2828
use core::time::Duration;
2929
use std::{fs::File, io::Write};
3030

@@ -42,7 +42,7 @@ fn main() {
4242
Startup,
4343
(save_scene_system, load_scene_system, infotext_system),
4444
)
45-
.add_systems(Update, log_system)
45+
.add_systems(Update, (log_system, panic_on_fail))
4646
.run();
4747
}
4848

@@ -226,3 +226,13 @@ fn infotext_system(mut commands: Commands) {
226226
},
227227
));
228228
}
229+
230+
/// To help with Bevy's automated testing, we want the example to close with an appropriate if the
231+
/// scene fails to load. This is most likely not something you want in your own app.
232+
fn panic_on_fail(scenes: Query<&DynamicSceneRoot>, asset_server: Res<AssetServer>) {
233+
for scene in &scenes {
234+
if let Some(LoadState::Failed(err)) = asset_server.get_load_state(&scene.0) {
235+
panic!("Failed to load scene. {}", err);
236+
}
237+
}
238+
}

0 commit comments

Comments
 (0)