Skip to content

Commit 1bed483

Browse files
66OJ6666OJ66
and
66OJ66
authored
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` - bevyengine/bevy#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 <[email protected]>
1 parent f0a6c84 commit 1bed483

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/lib.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,23 @@ impl GltfPlugin {
4040

4141
impl Plugin for GltfPlugin {
4242
fn build(&self, app: &mut App) {
43+
app.register_type::<GltfExtras>()
44+
.add_asset::<Gltf>()
45+
.add_asset::<GltfNode>()
46+
.add_asset::<GltfPrimitive>()
47+
.add_asset::<GltfMesh>();
48+
}
49+
50+
fn finish(&self, app: &mut App) {
4351
let supported_compressed_formats = match app.world.get_resource::<RenderDevice>() {
4452
Some(render_device) => CompressedImageFormats::from_features(render_device.features()),
4553

46-
None => CompressedImageFormats::all(),
54+
None => CompressedImageFormats::NONE,
4755
};
4856
app.add_asset_loader::<GltfLoader>(GltfLoader {
4957
supported_compressed_formats,
5058
custom_vertex_attributes: self.custom_vertex_attributes.clone(),
51-
})
52-
.register_type::<GltfExtras>()
53-
.add_asset::<Gltf>()
54-
.add_asset::<GltfNode>()
55-
.add_asset::<GltfPrimitive>()
56-
.add_asset::<GltfMesh>();
59+
});
5760
}
5861
}
5962

0 commit comments

Comments
 (0)