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
21 changes: 14 additions & 7 deletions crates/bevy_render/src/render_asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,6 @@ pub(crate) fn extract_render_asset<A: RenderAsset>(
let mut modified = <HashSet<_>>::default();

for event in events.read() {
#[expect(
clippy::match_same_arms,
reason = "LoadedWithDependencies is marked as a TODO, so it's likely this will no longer lint soon."
)]
match event {
AssetEvent::Added { id } => {
needs_extracting.insert(*id);
Expand All @@ -258,9 +254,20 @@ pub(crate) fn extract_render_asset<A: RenderAsset>(
needs_extracting.insert(*id);
modified.insert(*id);
}
AssetEvent::Removed { .. } => {
// We don't care that the asset was removed from Assets<T> in the main world.
// An asset is only removed from RenderAssets<T> when its last handle is dropped (AssetEvent::Unused).
AssetEvent::Removed { id, .. } => {
// Normally, we consider an asset removed from the render world only
// when it's final handle is dropped triggering an `AssetEvent::Unused`
// event. However, removal without unused can happen when the asset
// is explicitly removed from the asset server and re-added by the user.
// We mark the asset as modified in this case to ensure that
// any necessary render world bookkeeping still runs.

// TODO: consider removing this check and just emitting Unused after
// Removed to ensure that the asset is always "really" removed from the
// render world when the last strong handle is dropped.
if !removed.contains(id) {
modified.insert(*id);
}
}
AssetEvent::Unused { id } => {
needs_extracting.remove(id);
Expand Down