Skip to content
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
50 changes: 27 additions & 23 deletions framework_crates/bones_asset/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,27 +511,30 @@ impl AssetServer {
dependencies: partial.dependencies,
data: partial.data,
};

// If there is already loaded asset data for this path
if let Some((_, cid)) = server.store.asset_ids.remove(&handle) {
// Remove the old asset data
let (_, previous_asset) = server.store.assets.remove(&cid).unwrap();

// Remove the previous asset's reverse dependencies.
//
// aka. now that we are removing the old asset, none of the assets that the
// old asset dependended on should have a reverse dependency record saying that
// this asset depends on it.
//
// In other words, this asset is removed and doesn't depend on anything else
// anymore.
for dep in previous_asset.dependencies.iter() {
server
.store
.reverse_dependencies
.get_mut(dep)
.unwrap()
.remove(&handle);
if let Some(cid) = server.store.asset_ids.insert(handle, partial.cid) {
// If no other handles use this content
if server.store.asset_ids.iter().all(|map| *map.value() != cid) {
// Remove the old asset data
tracing::debug!(?cid, "Removing asset content");
let (_, previous_asset) = server.store.assets.remove(&cid).unwrap();

// Remove the previous asset's reverse dependencies.
//
// aka. now that we are removing the old asset, none of the assets that the
// old asset dependended on should have a reverse dependency record saying that
// this asset depends on it.
//
// In other words, this asset is removed and doesn't depend on anything else
// anymore.
for dep in previous_asset.dependencies.iter() {
server
.store
.reverse_dependencies
.get_mut(dep)
.unwrap()
.remove(&handle);
}
}

// If there are any assets that depended on this asset, they now need to be re-loaded.
Expand All @@ -555,7 +558,6 @@ impl AssetServer {
.insert(handle);
}

server.store.asset_ids.insert(handle, partial.cid);
server.store.assets.insert(partial.cid, loaded_asset);
server.load_progress.inc_loaded();

Expand Down Expand Up @@ -830,11 +832,13 @@ impl AssetServer {
///
/// # Panics
///
/// Panics if the asset is not loaded or if the asset asset with the given handle doesn't have a
/// Panics if the asset is not loaded or if the asset with the given handle doesn't have a
/// schema matching `T`.
#[track_caller]
pub fn get<T: HasSchema>(&self, handle: Handle<T>) -> MappedMapRef<Cid, LoadedAsset, T> {
self.try_get(handle).unwrap().unwrap()
self.try_get(handle)
.expect("asset not found (handle has no cid)")
.expect("asset does not have matching schema for given type")
}

/// Borrow a loaded asset.
Expand Down