Skip to content

Commit 1fb429b

Browse files
committed
Defer init of texture loaders via render_init callback
The texture loaders depend on being able to query a `RenderDevice` for supported compressed texture formats, and if no device is found they (silently) fallback to assuming `all()` formats are supported. This moves the initialization of the `ImageTextureLoader` and `HdrTextureLoader` asset loaders into the `.add_render_init()` callback in `ImagePlugin::build()` to ensure they are only initialized after the `RenderDevice` has been created. Tested with `examples/3d/texture.rs`
1 parent 4bcc32a commit 1fb429b

File tree

1 file changed

+18
-18
lines changed
  • crates/bevy_render/src/texture

1 file changed

+18
-18
lines changed

crates/bevy_render/src/texture/mod.rs

+18-18
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,6 @@ pub struct ImagePlugin;
3737

3838
impl Plugin for ImagePlugin {
3939
fn build(&self, app: &mut App) {
40-
#[cfg(any(
41-
feature = "png",
42-
feature = "dds",
43-
feature = "tga",
44-
feature = "jpeg",
45-
feature = "bmp",
46-
feature = "basis-universal",
47-
feature = "ktx2",
48-
))]
49-
{
50-
app.init_asset_loader::<ImageTextureLoader>();
51-
}
52-
53-
#[cfg(feature = "hdr")]
54-
{
55-
app.init_asset_loader::<HdrTextureLoader>();
56-
}
57-
5840
app.add_plugin(RenderAssetPlugin::<Image>::with_prepare_asset_label(
5941
PrepareAssetLabel::PreAssetPrepare,
6042
))
@@ -64,6 +46,24 @@ impl Plugin for ImagePlugin {
6446
.set_untracked(DEFAULT_IMAGE_HANDLE, Image::default());
6547

6648
app.add_render_init(move |app| {
49+
#[cfg(any(
50+
feature = "png",
51+
feature = "dds",
52+
feature = "tga",
53+
feature = "jpeg",
54+
feature = "bmp",
55+
feature = "basis-universal",
56+
feature = "ktx2",
57+
))]
58+
{
59+
app.init_asset_loader::<ImageTextureLoader>();
60+
}
61+
62+
#[cfg(feature = "hdr")]
63+
{
64+
app.init_asset_loader::<HdrTextureLoader>();
65+
}
66+
6767
if let Ok(render_app) = app.get_sub_app_mut(RenderApp) {
6868
render_app
6969
.init_resource::<TextureCache>()

0 commit comments

Comments
 (0)