Skip to content

Commit

Permalink
Do not crash if RenderDevice doesn't exist (bevyengine#4427)
Browse files Browse the repository at this point in the history
# Objective

Avoid crashing if `RenderDevice` doesn't exist (required for headless mode).
Fixes bevyengine#4392.

## Solution

Use `CompressedImageFormats::all()` if there is no `RenderDevice`.
  • Loading branch information
Shatur authored and aevyrie committed Jun 7, 2022
1 parent 01821b4 commit 0d63c4f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
9 changes: 6 additions & 3 deletions crates/bevy_gltf/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
}
Expand Down
9 changes: 6 additions & 3 deletions crates/bevy_render/src/texture/image_texture_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
}
Expand Down

0 comments on commit 0d63c4f

Please sign in to comment.