Skip to content

Commit

Permalink
Log errors when loading textures from a gltf file (#2260)
Browse files Browse the repository at this point in the history
When loading a gltf, if there is an error loading textures, it is completely ignored.

This can happen for example when loading a file with `jpg` textures without the `jpeg` Bevy feature enabled.
This PR adds `warn` logs for the few cases that can happen when loading a texture.

Other possible fix would be to break on first error and returning, making the asset loading failed
  • Loading branch information
mockersf committed Jun 8, 2021
1 parent 7913ebd commit f3deea1
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use bevy_asset::{
};
use bevy_core::Name;
use bevy_ecs::world::World;
use bevy_log::warn;
use bevy_math::Mat4;
use bevy_pbr::prelude::{PbrBundle, StandardMaterial};
use bevy_render::{
Expand Down Expand Up @@ -49,7 +50,7 @@ pub enum GltfError {
BufferFormatUnsupported,
#[error("invalid image mime type: {0}")]
InvalidImageMimeType(String),
#[error("{0}")]
#[error("You may need to add the feature for the file format: {0}")]
ImageError(#[from] TextureError),
#[error("failed to load an asset path: {0}")]
AssetIoError(#[from] AssetIoError),
Expand Down Expand Up @@ -262,7 +263,12 @@ async fn load_gltf<'a, 'b>(
});
})
.into_iter()
.filter_map(|result| result.ok())
.filter_map(|res| {
if let Err(err) = res.as_ref() {
warn!("Error loading GLTF texture: {}", err);
}
res.ok()
})
.for_each(|(texture, label)| {
load_context.set_labeled_asset(&label, LoadedAsset::new(texture));
});
Expand Down

0 comments on commit f3deea1

Please sign in to comment.