Search Unity

Bug Editor doesn't clear cache properly if interrupted during loading

Discussion in 'Asset Bundles' started by LaneFox, Apr 17, 2023.

  1. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,521
    In the Editor during asset bundle loading it seems like if you stop playing while the bundles are being loaded then they'll be stuck in the Editor cache somewhere and the API doesn't seem to clear them out when called.

    For example, I interrupt the loading process by pressing play to stop the editor play mode while the bundles are loading in. I have the following code on the loading system component:

    Code (csharp):
    1.         private void OnDestroy()
    2.         {
    3.              Caching.ClearCache();
    4.              foreach (AssetBundle b in AssetBundle.GetAllLoadedAssetBundles()) b.Unload(true);
    5.         }
    The code above does not throw, but if I press play again then the bundle system will throw this:

    So it seems like despite calling the necessary code to clear the caches out, they don't seem to work because the bundle probably wasn't fully loaded, and thus is hanging around somewhere halfway but not actually documented as a loaded bundle.

    In order to be able to get around this I've been forcing a recompile and it seems to clean up and allow me to run the loading process properly.
     
  2. AndrewSkow

    AndrewSkow

    Unity Technologies

    Joined:
    Nov 17, 2020
    Posts:
    91
  3. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,521
    Thanks for the reply.

    We're not using scene bundles, just assets. This only occurs when the bundle load/import process is interrupted by exiting play mode.
     
  4. AndrewSkow

    AndrewSkow

    Unity Technologies

    Joined:
    Nov 17, 2020
    Posts:
    91
    OK, thanks for confirming that it is not related to Scene bundles. This sounds to me like a bug in the error handling code path, e.g. something along the lines of what you described of some state not being cleaned up. I do not think that is logged anywhere as a bug so a bug report would be very helpful.
     
    LaneFox likes this.
  5. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,521
    Thanks. I can't submit the existing project but I've made a ticket internally to build something to repro and report the issue. I'll note the bug id here when we eventually get around to it.