Skip to content

Commit

Permalink
Useful error message when two assets have the save UUID (#3739)
Browse files Browse the repository at this point in the history
# Objective
Fixes #2610 and #3731

## Solution

Added check for TYPE_UUID duplication in  `register_asset_type` with an error message
  • Loading branch information
ShadowCurse committed Feb 12, 2022
1 parent 0ccb9dd commit 62329f7
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions crates/bevy_asset/src/asset_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,19 @@ impl AssetServer {
}

pub(crate) fn register_asset_type<T: Asset>(&self) -> Assets<T> {
self.server.asset_lifecycles.write().insert(
T::TYPE_UUID,
Box::new(AssetLifecycleChannel::<T>::default()),
);
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);
}
Assets::new(self.server.asset_ref_counter.channel.sender.clone())
}

Expand Down

0 comments on commit 62329f7

Please sign in to comment.