Only send unused event when final handle is dropped. (#18641)

# Objective

Fixes #18457

## Solution

Move the Unused even after the check for existing strong handles.
This commit is contained in:
charlotte 2025-03-31 11:05:59 -07:00 committed by GitHub
parent 89e00b19c4
commit c44dd39bdd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -462,16 +462,22 @@ impl<A: Asset> Assets<A> {
/// Removes the [`Asset`] with the given `id`.
pub(crate) fn remove_dropped(&mut self, id: AssetId<A>) {
match self.duplicate_handles.get_mut(&id) {
None | Some(0) => {}
None => {}
Some(0) => {
self.duplicate_handles.remove(&id);
}
Some(value) => {
*value -= 1;
return;
}
}
let existed = match id {
AssetId::Index { index, .. } => self.dense_storage.remove_dropped(index).is_some(),
AssetId::Uuid { uuid } => self.hash_map.remove(&uuid).is_some(),
};
self.queued_events.push(AssetEvent::Unused { id });
if existed {
self.queued_events.push(AssetEvent::Removed { id });
}
@ -553,7 +559,6 @@ impl<A: Asset> Assets<A> {
}
}
assets.queued_events.push(AssetEvent::Unused { id });
assets.remove_dropped(id);
}
}