Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Panic on failure in scene example #17812

Merged
merged 1 commit into from
Feb 11, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions examples/scene/scene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand All @@ -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();
}

Expand Down Expand Up @@ -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