Skip to content
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 by Bors] - Useful error message when two assets have the save UUID #3739

Closed
Changes from 1 commit
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
9 changes: 9 additions & 0 deletions crates/bevy_asset/src/asset_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,15 @@ impl AssetServer {
}

pub(crate) fn register_asset_type<T: Asset>(&self) -> Assets<T> {
if self
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rather than grab a read lock and then a write lock immediately after, I think we should just grab a single write lock and reuse it across both cases (especially given that the "read only" case is the "unexpected" / "uncommon" case).

.server
.asset_lifecycles
.read()
.contains_key(&T::TYPE_UUID)
{
panic!("Error while registering new asset type. Asset with UUID: {:?} is already registered. Can not register another type with the same UUID",
T::TYPE_UUID);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you also log std::any::type_name::<T>() in the error?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally it would be possible to include the type name of the first type too, although I don't know if we store that information

Copy link
Contributor Author

@ShadowCurse ShadowCurse Feb 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added type name, but i don't think there is a way to get the original type. We only have trait object, so we can't get the type from it.

}
self.server.asset_lifecycles.write().insert(
T::TYPE_UUID,
Box::new(AssetLifecycleChannel::<T>::default()),
Expand Down