send Unused event when asset is actually unused#12459
send Unused event when asset is actually unused#12459alice-i-cecile merged 8 commits intobevyengine:mainfrom
Conversation
|
this was added in #10520 to allow removing assets from the cpu side and keeping them on the gpu side |
Agreed. Different PR of course, so then we can ship this in 0.13.1.
This makes sense to me too. |
|
@JMS55 on discord:
i missed that so instead we can use the existing logic for processing the automatic removal (in |
bushrat011899
left a comment
There was a problem hiding this comment.
Mostly just some minor style suggestions. Otherwise, makes sense!
|
i think the resending of |
No :) |
nope, the code is fine, sorry. i think this is good as is |
|
Tbh I'm having a hard time reviewing this, as the code is a bit confusing. I'm not quite sure I understand the implications of moving it around like this. |
Have a look at the related issue. the important thing is that the process_handle_drop call checks whether new handles have been created since the drop event was fired, before removing the asset. We now perform that check before sending the unused event as well. |
| assets.remove_dropped(id); | ||
|
|
||
| if !infos.process_handle_drop(untyped_id) { | ||
| // a new handle has been created, or the asset doesn't exist |
There was a problem hiding this comment.
Can we expand this comment a bit with the context you put in your last comment to me? That this is a check to see if a new handle has been created in the same frame after the last one was dropped, meaning it's not actually unused.
Also, what does "or the asset doesn't exist" mean here?
There was a problem hiding this comment.
it's what the comment in the process_handle_drop function says. i don't know a scenario where it would happen.
JMS55
left a comment
There was a problem hiding this comment.
Thanks that clears it up for me. Approved, but I'd like some more verbose doc comments.
fix #12344 use existing machinery in track_assets to determine if the asset is unused before firing Asset::Unused event ~~most extract functions use `AssetEvent::Removed` to schedule deletion of render world resources. `RenderAssetPlugin` was using `AssetEvent::Unused` instead. `Unused` fires when the last strong handle is dropped, even if a new one is created. `Removed` only fires when a new one is not created. as far as i can see, `Unused` is the same as `Removed` except for this "feature", and that it also fires early if all handles for a loading asset are dropped (`Removed` fires after the loading completes). note that in that case, processing based on `Loaded` won't have been done anyway. i think we should get rid of `Unused` completely, it is not currently used anywhere (except here, previously) and i think using it is probably always a mistake. i also am not sure why we keep loading assets that have been dropped while loading, we should probably drop the loader task as well and remove immediately.~~
Objective
fix #12344
Solution
use existing machinery in track_assets to determine if the asset is unused before firing Asset::Unused event
most extract functions use
AssetEvent::Removedto schedule deletion of render world resources.RenderAssetPluginwas usingAssetEvent::Unusedinstead.Unusedfires when the last strong handle is dropped, even if a new one is created.Removedonly fires when a new one is not created.as far as i can see,
Unusedis the same asRemovedexcept for this "feature", and that it also fires early if all handles for a loading asset are dropped (Removedfires after the loading completes). note that in that case, processing based onLoadedwon't have been done anyway.i think we should get rid of
Unusedcompletely, it is not currently used anywhere (except here, previously) and i think using it is probably always a mistake.i also am not sure why we keep loading assets that have been dropped while loading, we should probably drop the loader task as well and remove immediately.