From 67bbfb08f8de20e4e52964b7155505f2384b6c12 Mon Sep 17 00:00:00 2001 From: Hennadii Chernyshchyk Date: Tue, 5 Apr 2022 19:37:23 +0000 Subject: [PATCH] Do not crash if RenderDevice doesn't exist (#4427) # Objective Avoid crashing if `RenderDevice` doesn't exist (required for headless mode). Fixes #4392. ## Solution Use `CompressedImageFormats::all()` if there is no `RenderDevice`. --- crates/bevy_gltf/src/loader.rs | 9 ++++++--- crates/bevy_render/src/texture/image_texture_loader.rs | 9 ++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/crates/bevy_gltf/src/loader.rs b/crates/bevy_gltf/src/loader.rs index 4680cce54844dd..e68f326d0a101d 100644 --- a/crates/bevy_gltf/src/loader.rs +++ b/crates/bevy_gltf/src/loader.rs @@ -88,10 +88,13 @@ impl AssetLoader for GltfLoader { impl FromWorld for GltfLoader { fn from_world(world: &mut World) -> Self { + let supported_compressed_formats = match world.get_resource::() { + Some(render_device) => CompressedImageFormats::from_features(render_device.features()), + + None => CompressedImageFormats::all(), + }; Self { - supported_compressed_formats: CompressedImageFormats::from_features( - world.resource::().features(), - ), + supported_compressed_formats, } } } diff --git a/crates/bevy_render/src/texture/image_texture_loader.rs b/crates/bevy_render/src/texture/image_texture_loader.rs index 46be9ba0f9bbcb..a5eb931acfa3b3 100644 --- a/crates/bevy_render/src/texture/image_texture_loader.rs +++ b/crates/bevy_render/src/texture/image_texture_loader.rs @@ -69,10 +69,13 @@ impl AssetLoader for ImageTextureLoader { impl FromWorld for ImageTextureLoader { fn from_world(world: &mut World) -> Self { + let supported_compressed_formats = match world.get_resource::() { + Some(render_device) => CompressedImageFormats::from_features(render_device.features()), + + None => CompressedImageFormats::all(), + }; Self { - supported_compressed_formats: CompressedImageFormats::from_features( - world.resource::().features(), - ), + supported_compressed_formats, } } }