Skip to content

Fix asset loader registration warning #11870

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions crates/bevy_asset/src/server/loaders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{
path::AssetPath,
};
use async_broadcast::RecvError;
use bevy_log::{error, info, warn};
use bevy_log::{error, warn};
use bevy_tasks::IoTaskPool;
use bevy_utils::{HashMap, TypeIdMap};
use std::{any::TypeId, sync::Arc};
Expand Down Expand Up @@ -40,14 +40,15 @@ impl AssetLoaders {
};

if is_new {
let mut duplicate_extensions = Vec::new();
for extension in loader.extensions() {
let list = self
.extension_to_loaders
.entry(extension.to_string())
.or_default();

if !list.is_empty() {
warn!("duplicate registration for extension `{extension}`.");
duplicate_extensions.push(extension);
}

list.push(loader_index);
Expand All @@ -60,8 +61,10 @@ impl AssetLoaders {
.entry(loader_asset_type)
.or_default();

if !list.is_empty() {
info!("duplicate registration for type `{loader_asset_type_name}`.");
let duplicate_asset_registration = !list.is_empty();
if !duplicate_extensions.is_empty() && duplicate_asset_registration {
warn!("Duplicate AssetLoader registered for Asset type `{loader_asset_type_name}` with extensions `{duplicate_extensions:?}`. \
Loader must be specified in a .meta file in order to load assets of this type with these extensions.");
}

list.push(loader_index);
Expand Down Expand Up @@ -98,14 +101,15 @@ impl AssetLoaders {

self.preregistered_loaders.insert(type_name, loader_index);
self.type_name_to_loader.insert(type_name, loader_index);
let mut duplicate_extensions = Vec::new();
for extension in extensions {
let list = self
.extension_to_loaders
.entry(extension.to_string())
.or_default();

if !list.is_empty() {
warn!("duplicate preregistration for extension `{extension}`.");
duplicate_extensions.push(extension);
}

list.push(loader_index);
Expand All @@ -116,8 +120,10 @@ impl AssetLoaders {
.entry(loader_asset_type)
.or_default();

if !list.is_empty() {
info!("duplicate preregistration for type `{loader_asset_type_name}`.");
let duplicate_asset_registration = !list.is_empty();
if !duplicate_extensions.is_empty() && duplicate_asset_registration {
warn!("Duplicate AssetLoader preregistered for Asset type `{loader_asset_type_name}` with extensions `{duplicate_extensions:?}`. \
Loader must be specified in a .meta file in order to load assets of this type with these extensions.");
}

list.push(loader_index);
Expand Down