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 3 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
7 changes: 6 additions & 1 deletion crates/bevy_asset/src/asset_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,12 @@ impl AssetServer {
}

pub(crate) fn register_asset_type<T: Asset>(&self) -> Assets<T> {
self.server.asset_lifecycles.write().insert(
let mut asset_lifecycles = self.server.asset_lifecycles.write();
if asset_lifecycles.contains_key(&T::TYPE_UUID) {
panic!("Error while registering new asset type: {:?} with UUID: {:?}. Another type with the same UUID is already registered. Can not register new asset type with the same UUID",
std::any::type_name::<T>(), T::TYPE_UUID);
}
asset_lifecycles.insert(
T::TYPE_UUID,
Box::new(AssetLifecycleChannel::<T>::default()),
);
Copy link
Member

Choose a reason for hiding this comment

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

insert would return Some(_) if the value already exists, so this could be just

        if self
            .server
            .asset_lifecycles
            .write()
            .insert(
                T::TYPE_UUID,
                Box::new(AssetLifecycleChannel::<T>::default()),
            )
            .is_some()
        {
            panic!("Error while registering new asset type: {:?} with UUID: {:?}. Another type with the same UUID is already registered. Can not register new asset type with the same UUID.",
            std::any::type_name::<T>(), T::TYPE_UUID);
        }

Expand Down