Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question HDRP 7.1.8 - SkyRenderer Memory Leak

Discussion in 'Editor & General Support' started by noam_2000, Feb 18, 2021.

  1. noam_2000

    noam_2000

    Joined:
    Sep 14, 2017
    Posts:
    18
    Hi everyone - we've recently stumbled upon a very serious issue with our game and are in need of dire help.

    The Unity version we're using is 2019.3.7f1, and HDRP 7.1.8 as the SRP. The issue we're experiencing is that every time we switch scenes, the memory usage of our game jumps drastically without getting freed. With enough scene-switching, this can also lead to an out-of-memory crash.

    From investigation, we've discovered it is HDRP's Sky Renderer which is failing to unload (and for the record, most if not all of our usage of visual environments is of HDRI Sky type). We've even debugged the HDRI sky code to find out that the "Cleanup()" method never gets called, while the others get called just fine.



    HDRP 7.2.0's changelog mentions the following:
    • Fixed a leak in sky manager.
    And while I can't verify for sure if this is the same leak, I can pretty much count on it. The issue is that we're absolutely unable to upgrade our HDRP version beyond 7.1.8. Trust me, there were many attempts - our project does not convert at all beyond what we have right now and there's too many issues for us to handle with said upgrade.

    Obviously though, we can't ship with this dire of a memory leak. We're very desperate for any help we can get with getting around this issue on 7.1.8. Even any kind of direction or tips would be massively appreciated. Thank you!
     
  2. noam_2000

    noam_2000

    Joined:
    Sep 14, 2017
    Posts:
    18
    Also worth mentioning: switching out the pipeline asset at runtime stabilizes the memory usage, flushing all the unused resources from memory - though I still find it to be too costly to do at every scene switch, especially since it would need to be done twice (once with a different pipeline asset to register the change, and again for reverting to the original asset.)

    I suppose one idea could be to create a duplicate of each pipeline asset, and switch them at every scene switch - so we only have to perform one asset switch. Still, I'd love to hear better solutions than this..
     
    Last edited: Feb 18, 2021
  3. prefetcher

    prefetcher

    Joined:
    Oct 8, 2019
    Posts:
    4
    After a bit of research, I've concluded that the bug is mostly caused by HDRP not unloading the cached sky rendering contexts that are created per level and then stored/cached in the "m_CachedSkyContexts" dynamic array inside of HDRP's SkyManager. Manually calling ".Cleanup()" on all of the objects in that array, on every single level load actually makes HDRP unload all of the previously allocated assets, with absolutely no performance hit.

    Below is the code that we use as a patch within our game, to clean up all of the unused textures. We call it right after SceneManager finishes loading the scene.

    public void ClearSkyContexts()
    {
    for (int i = 0; i < m_CachedSkyContexts.size; ++i)
    m_CachedSkyContexts[i].Cleanup();
    }
     
  4. pixelsplit

    pixelsplit

    Joined:
    Sep 16, 2013
    Posts:
    173
    I have to bump this thread again. Seems like we have the same problem with 2022.3 + HDRP. The leaks are so big over a playsession that it crashes eventually.

    It seems like m_CachedSkyContext and the SkyManager are internal and not accessible. How did you do it? Customized HD Render Pipeline?

    Here is the approved bug report, but don't expect it to be fixed soon ... https://issuetracker.unity3d.com/is...y-when-using-cubemaparrays-and-rendertextures
     
  5. noam_2000

    noam_2000

    Joined:
    Sep 14, 2017
    Posts:
    18
    Yes, we've had to extract it from the package and create a tailored HD rendering pipeline with a bunch of our own fixes applied.