Skip to content

Commit ea6e6f7

Browse files
committed
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`.
1 parent dbb2fcb commit ea6e6f7

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

crates/bevy_gltf/src/loader.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,13 @@ impl AssetLoader for GltfLoader {
8888

8989
impl FromWorld for GltfLoader {
9090
fn from_world(world: &mut World) -> Self {
91+
let supported_compressed_formats = match world.get_resource::<RenderDevice>() {
92+
Some(render_device) => CompressedImageFormats::from_features(render_device.features()),
93+
94+
None => CompressedImageFormats::all(),
95+
};
9196
Self {
92-
supported_compressed_formats: CompressedImageFormats::from_features(
93-
world.resource::<RenderDevice>().features(),
94-
),
97+
supported_compressed_formats,
9598
}
9699
}
97100
}

crates/bevy_render/src/texture/image_texture_loader.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,13 @@ impl AssetLoader for ImageTextureLoader {
6969

7070
impl FromWorld for ImageTextureLoader {
7171
fn from_world(world: &mut World) -> Self {
72+
let supported_compressed_formats = match world.get_resource::<RenderDevice>() {
73+
Some(render_device) => CompressedImageFormats::from_features(render_device.features()),
74+
75+
None => CompressedImageFormats::all(),
76+
};
7277
Self {
73-
supported_compressed_formats: CompressedImageFormats::from_features(
74-
world.resource::<RenderDevice>().features(),
75-
),
78+
supported_compressed_formats,
7679
}
7780
}
7881
}

0 commit comments

Comments
 (0)