Panic on failure in scene
example (#17812)
# Objective Fixes #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
This commit is contained in:
parent
94deca81bf
commit
7398d33b79
@ -24,7 +24,7 @@
|
||||
//! won't work on WASM because WASM typically doesn't have direct filesystem access.
|
||||
//!
|
||||
|
||||
use bevy::{prelude::*, tasks::IoTaskPool};
|
||||
use bevy::{asset::LoadState, prelude::*, tasks::IoTaskPool};
|
||||
use core::time::Duration;
|
||||
use std::{fs::File, io::Write};
|
||||
|
||||
@ -42,7 +42,7 @@ fn main() {
|
||||
Startup,
|
||||
(save_scene_system, load_scene_system, infotext_system),
|
||||
)
|
||||
.add_systems(Update, log_system)
|
||||
.add_systems(Update, (log_system, panic_on_fail))
|
||||
.run();
|
||||
}
|
||||
|
||||
@ -226,3 +226,13 @@ fn infotext_system(mut commands: Commands) {
|
||||
},
|
||||
));
|
||||
}
|
||||
|
||||
/// To help with Bevy's automated testing, we want the example to close with an appropriate if the
|
||||
/// scene fails to load. This is most likely not something you want in your own app.
|
||||
fn panic_on_fail(scenes: Query<&DynamicSceneRoot>, asset_server: Res<AssetServer>) {
|
||||
for scene in &scenes {
|
||||
if let Some(LoadState::Failed(err)) = asset_server.get_load_state(&scene.0) {
|
||||
panic!("Failed to load scene. {}", err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user