Skip to content

Fix duplicate asset loader registration warning #17105

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
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
53 changes: 31 additions & 22 deletions crates/bevy_asset/src/server/loaders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ impl AssetLoaders {
};

if is_new {
let existing_loaders_for_type_id = self.type_id_to_loaders.get(&loader_asset_type);
let mut duplicate_extensions = Vec::new();
for extension in AssetLoader::extensions(&*loader) {
let list = self
Expand All @@ -54,26 +55,29 @@ impl AssetLoaders {
.or_default();

if !list.is_empty() {
duplicate_extensions.push(extension);
if let Some(existing_loaders_for_type_id) = existing_loaders_for_type_id {
if list
.iter()
.any(|index| existing_loaders_for_type_id.contains(index))
{
duplicate_extensions.push(extension);
}
}
}

list.push(loader_index);
}

self.type_name_to_loader.insert(type_name, loader_index);

let list = self
.type_id_to_loaders
.entry(loader_asset_type)
.or_default();

let duplicate_asset_registration = !list.is_empty();
if !duplicate_extensions.is_empty() && duplicate_asset_registration {
if !duplicate_extensions.is_empty() {
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);
self.type_name_to_loader.insert(type_name, loader_index);

self.type_id_to_loaders
.entry(loader_asset_type)
.or_default()
.push(loader_index);

self.loaders.push(MaybeAssetLoader::Ready(loader));
} else {
Expand Down Expand Up @@ -107,6 +111,8 @@ impl AssetLoaders {

self.preregistered_loaders.insert(type_name, loader_index);
self.type_name_to_loader.insert(type_name, loader_index);

let existing_loaders_for_type_id = self.type_id_to_loaders.get(&loader_asset_type);
let mut duplicate_extensions = Vec::new();
for extension in extensions {
let list = self
Expand All @@ -115,24 +121,27 @@ impl AssetLoaders {
.or_default();

if !list.is_empty() {
duplicate_extensions.push(extension);
if let Some(existing_loaders_for_type_id) = existing_loaders_for_type_id {
if list
.iter()
.any(|index| existing_loaders_for_type_id.contains(index))
{
duplicate_extensions.push(extension);
}
}
}

list.push(loader_index);
}

let list = self
.type_id_to_loaders
.entry(loader_asset_type)
.or_default();

let duplicate_asset_registration = !list.is_empty();
if !duplicate_extensions.is_empty() && duplicate_asset_registration {
if !duplicate_extensions.is_empty() {
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);
self.type_id_to_loaders
.entry(loader_asset_type)
.or_default()
.push(loader_index);

let (mut sender, receiver) = async_broadcast::broadcast(1);
sender.set_overflow(true);
Expand Down
Loading