Skip to content

Commit a9b0b4e

Browse files
authored
Mark render assets as modified when removed from the asset server (#18814)
# Objective Fixes #18808 ## Solution When an asset emits a removed event, mark it as modified in the render world to ensure any appropriate bookkeeping runs as necessary.
1 parent e9a0ef4 commit a9b0b4e

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

crates/bevy_render/src/render_asset.rs

+14-7
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,6 @@ pub(crate) fn extract_render_asset<A: RenderAsset>(
246246
let mut modified = <HashSet<_>>::default();
247247

248248
for event in events.read() {
249-
#[expect(
250-
clippy::match_same_arms,
251-
reason = "LoadedWithDependencies is marked as a TODO, so it's likely this will no longer lint soon."
252-
)]
253249
match event {
254250
AssetEvent::Added { id } => {
255251
needs_extracting.insert(*id);
@@ -258,9 +254,20 @@ pub(crate) fn extract_render_asset<A: RenderAsset>(
258254
needs_extracting.insert(*id);
259255
modified.insert(*id);
260256
}
261-
AssetEvent::Removed { .. } => {
262-
// We don't care that the asset was removed from Assets<T> in the main world.
263-
// An asset is only removed from RenderAssets<T> when its last handle is dropped (AssetEvent::Unused).
257+
AssetEvent::Removed { id, .. } => {
258+
// Normally, we consider an asset removed from the render world only
259+
// when it's final handle is dropped triggering an `AssetEvent::Unused`
260+
// event. However, removal without unused can happen when the asset
261+
// is explicitly removed from the asset server and re-added by the user.
262+
// We mark the asset as modified in this case to ensure that
263+
// any necessary render world bookkeeping still runs.
264+
265+
// TODO: consider removing this check and just emitting Unused after
266+
// Removed to ensure that the asset is always "really" removed from the
267+
// render world when the last strong handle is dropped.
268+
if !removed.contains(id) {
269+
modified.insert(*id);
270+
}
264271
}
265272
AssetEvent::Unused { id } => {
266273
needs_extracting.remove(id);

0 commit comments

Comments
 (0)