From 1bed483036d0101018cffae2e72584bd1e3f8f39 Mon Sep 17 00:00:00 2001 From: 66OJ66 <59021291+66OJ66@users.noreply.github.com> Date: Sun, 23 Jul 2023 01:27:37 +0000 Subject: [PATCH] Fix panic whilst loading UASTC encoded ktx2 textures (#9158) # Objective Fixes #9121 Context: - `ImageTextureLoader` depends on `RenderDevice` to work out which compressed image formats it can support - `RenderDevice` is initialised by `RenderPlugin` - https://github.com/bevyengine/bevy/pull/8336 made `RenderPlugin` initialisation async - This caused `RenderDevice` to be missing at the time of `ImageTextureLoader` initialisation, which in turn meant UASTC encoded ktx2 textures were being converted to unsupported formats, and thus caused panics ## Solution - Delay `ImageTextureLoader` initialisation --- ## Changelog - Moved `ImageTextureLoader` initialisation from `ImagePlugin::build()` to `ImagePlugin::finish()` - Default to `CompressedImageFormats::NONE` if `RenderDevice` resource is missing --------- Co-authored-by: 66OJ66 --- src/lib.rs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 7277a90..fc022bf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -40,20 +40,23 @@ impl GltfPlugin { impl Plugin for GltfPlugin { fn build(&self, app: &mut App) { + app.register_type::() + .add_asset::() + .add_asset::() + .add_asset::() + .add_asset::(); + } + + fn finish(&self, app: &mut App) { let supported_compressed_formats = match app.world.get_resource::() { Some(render_device) => CompressedImageFormats::from_features(render_device.features()), - None => CompressedImageFormats::all(), + None => CompressedImageFormats::NONE, }; app.add_asset_loader::(GltfLoader { supported_compressed_formats, custom_vertex_attributes: self.custom_vertex_attributes.clone(), - }) - .register_type::() - .add_asset::() - .add_asset::() - .add_asset::() - .add_asset::(); + }); } }