Skip to content

Commit

Permalink
Defer init of texture loaders via render_init callback
Browse files Browse the repository at this point in the history
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`
  • Loading branch information
rib committed Jun 5, 2022
1 parent 4bcc32a commit 1fb429b
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions crates/bevy_render/src/texture/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,6 @@ pub struct ImagePlugin;

impl Plugin for ImagePlugin {
fn build(&self, app: &mut App) {
#[cfg(any(
feature = "png",
feature = "dds",
feature = "tga",
feature = "jpeg",
feature = "bmp",
feature = "basis-universal",
feature = "ktx2",
))]
{
app.init_asset_loader::<ImageTextureLoader>();
}

#[cfg(feature = "hdr")]
{
app.init_asset_loader::<HdrTextureLoader>();
}

app.add_plugin(RenderAssetPlugin::<Image>::with_prepare_asset_label(
PrepareAssetLabel::PreAssetPrepare,
))
Expand All @@ -64,6 +46,24 @@ impl Plugin for ImagePlugin {
.set_untracked(DEFAULT_IMAGE_HANDLE, Image::default());

app.add_render_init(move |app| {
#[cfg(any(
feature = "png",
feature = "dds",
feature = "tga",
feature = "jpeg",
feature = "bmp",
feature = "basis-universal",
feature = "ktx2",
))]
{
app.init_asset_loader::<ImageTextureLoader>();
}

#[cfg(feature = "hdr")]
{
app.init_asset_loader::<HdrTextureLoader>();
}

if let Ok(render_app) = app.get_sub_app_mut(RenderApp) {
render_app
.init_resource::<TextureCache>()
Expand Down

0 comments on commit 1fb429b

Please sign in to comment.