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`.
This commit is contained in:
Hennadii Chernyshchyk 2022-04-05 19:37:23 +00:00
parent dbb2fcb677
commit ea6e6f7db2
2 changed files with 12 additions and 6 deletions

View File

@ -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::<RenderDevice>() {
Some(render_device) => CompressedImageFormats::from_features(render_device.features()),
None => CompressedImageFormats::all(),
};
Self {
supported_compressed_formats: CompressedImageFormats::from_features(
world.resource::<RenderDevice>().features(),
),
supported_compressed_formats,
}
}
}

View File

@ -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::<RenderDevice>() {
Some(render_device) => CompressedImageFormats::from_features(render_device.features()),
None => CompressedImageFormats::all(),
};
Self {
supported_compressed_formats: CompressedImageFormats::from_features(
world.resource::<RenderDevice>().features(),
),
supported_compressed_formats,
}
}
}