Search Unity

Bug Memory leak and crash in UnityGfxDeviceWorker

Discussion in 'iOS and tvOS' started by rumorgames, Feb 1, 2024.

  1. rumorgames

    rumorgames

    Joined:
    Nov 28, 2012
    Posts:
    48
    Disclaimer: I've already reported this bug, but Issue Tracker is apparently where bugs go to die so posting here for increased visibility

    https://issuetracker.unity3d.com/is...in-unitygfxdeviceworker-when-starting-the-app

    I've been having an issue that immediately and catastrophically runs up the memory usage on certain iOS devices (reported on iPad Pro, personally confirmed with iPad mini 6, Unity QA confirmed on multiple iPhones).

    Unfortunately the root of the crash is in code I have not written. It's caused by the asset FLOW by @Darkcoder and has been a known issue for nearly a year. While the developer has been of no help, my own subsequent investigation seems to point to it being a Unity bug (since confirmed by QA).

    On devices where the issue does not express, memory usage is normal:

    Screenshot 2023-10-13 at 2.12.15 PM.png

    On devices where the bug is present, memory usage spikes immediately causing iOS to force-close the app:

    Screenshot 2023-10-13 at 12.06.59 PM.png

    The callstack is not very helpful, and I haven't had much luck diagnosing a more specific culprit:

    Screenshot 2023-10-13 at 12.07.16 PM.png

    The problem seems to be related to AsyncGPUReadback as disabling all functionality related to readback prevents the bug from appearing. There doesn't appear to be anything wrong with the code specifically targeting these devices as far as I can tell, which ultimately leaves Unity as the source of the problem.

    But since this issue seems rarely stumbled upon outside of users of this one unpopular asset, I'm having a hell of a time getting attention on a fix. Any help would be greatly appreciated.
     
  2. rumorgames

    rumorgames

    Joined:
    Nov 28, 2012
    Posts:
    48
    Here is another investigation/demonstration of the issue. Running my project on an iPad mini 6 generates the following allocations, quickly exceeding the memory limit with thousands of unfreed allocations in a few seconds:

    iPad mini 6.png

    The same project running on iPhone 13 mini generates no runaway allocations. The stack in question is still the heaviest performance-wise but does not leak memory and crash:

    iPhone 13 mini.png

    I'm glad to see this was at least acknowledged as a known issue in the latest LTS release notes, but as yet there is no indication a solution is being worked on.

    If there is anything I could do on my end to work around the issue I would love to hear it. This crash has been frustrating me and my players for too long.
     
  3. Alexey

    Alexey

    Unity Technologies

    Joined:
    May 10, 2010
    Posts:
    1,624
    The problem seem to be quite different: "something" in FLOW plugin startup is too heavy/non-suitable for mobiles - it essentially hangs the gpu (thats what driver is saying - i would bet on simple "needs too long to process" but i don't know for sure) and this uncontrolled memory grows happens because drawable are requested and never presented (because gpu is busy)
     
  4. rumorgames

    rumorgames

    Joined:
    Nov 28, 2012
    Posts:
    48
    Thanks for your response @Alexey.

    Different from what/different how? The crash in unitygfxdeviceworker is an out-of-memory exception caused by this runaway memory growth. Digging in it's clear that the drawable being requested repeatedly is what is causing the memory to balloon, which causes the crash. But I don't understand why this happens. The same code does not cause any such issue on far lower-spec mobile devices than the iPad mini 6 (iPhone X and Samsung Galaxy A41 work fine, for example).
     
  5. Alexey

    Alexey

    Unity Technologies

    Joined:
    May 10, 2010
    Posts:
    1,624
    i cannot tell you THE reason (i didnt find it, hopefully not yet), but disabling async readback doesnt help at all (well, locally on iphone 14 smth).
     
  6. rumorgames

    rumorgames

    Joined:
    Nov 28, 2012
    Posts:
    48
    The fact that it runs on a potato like the A41 demonstrates it's objectively not "too heavy/non-suitable for mobiles." The problem only presents on a few top-of-the-line iOS devices. Your iPhone 14 has a better GPU than half the laptops on Steam. It generally works fine on mobile.

    And this is normal/expected behavior?

    That doesn't surprise me, AsyncGPUReadback was just a hunch as readback is one place in the code where new materials are created.

    I've already spent a great deal of time trying to track down if anything user-facing is putting excess strain on the GPU and lowered the performance impacts of the simulation to absurdly minimal levels. It still triggers the runaway memory bug.
     
  7. extstkim

    extstkim

    Joined:
    Jul 26, 2021
    Posts:
    3
  8. rumorgames

    rumorgames

    Joined:
    Nov 28, 2012
    Posts:
    48
    No. I don't see a path forward without a fix from Unity.

    @Alexey, any thoughts?