Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Bug [OpenXR] Player/Editor Memory Leaking with Oculus Runtime

Discussion in 'VR' started by AndreasWang, Jul 6, 2021.

  1. AndreasWang

    AndreasWang

    Joined:
    Jul 31, 2019
    Posts:
    24
    There seems to be a memory leak whenever I use the OpenXR plugin together with the Oculus OpenXR runtime which has been causing a fair share of issues. Whenever OpenXR transitions from a focused to idle state (i.e. taking a Rift S HMD on and then off your head), it looks like CanvasBatchRenderers will start to gradually increase how much memory it is spending. The speed of this leak also seems to be proportional to the amount of canvases or UI elements there are in the active scene.

    If I take the controller sample scene from the OpenXR plugin, add a camera space canvas which I then add a few hundred child buttons under with their own canvases, I end up with the following after a few seconds:
    1.png
    If I let it run for an extra minute or two it starts to look like this:
    2.png

    There does not seem to be a hard cap for how much memory CanvasBatchRenderers can eat up as I've managed to let it run for long enough to eat up ~14-15GB worth of RAM and cause major system slowdowns.

    Has anyone else experienced the same issue or found potential ways to work around it? (outside of disabling XR as soon as OpenXR goes to idle state. Doing that could end up being pretty tedious if you quickly take your headset off/on to check something on your desktop). I've submitted a bug report for the issue (#1344762), so hopefully it ends up being fixable soon enough.
     
  2. yarsrvenge

    yarsrvenge

    Joined:
    Jun 25, 2019
    Posts:
    87
    Hey. I actually reached out on the Oculus dev forums and Unity replied to me there about this:

    "We've seen reports of a memory leak on headset idle when using UI Canvases. We're working on getting a fix released."

    He said it required a fix in core Unity, not OpenXR. A workaround was supposedly disabling canvases when OpenXR reports a state change to IDLE, but that will be more trouble than its worth for me so I'm waiting on the fix.

    https://docs.unity3d.com/Packages/c...SessionStateChange_System_Int32_System_Int32_
     
    AndreasWang likes this.
  3. Cloudwalker_

    Cloudwalker_

    Joined:
    Jan 3, 2014
    Posts:
    141
    Noticed memory leaks over past year even in Oculus legacy and oculus plugin.
     
  4. the_real_apoxol

    the_real_apoxol

    Unity Technologies

    Joined:
    Dec 18, 2020
    Posts:
    467
    We have found and fixed one leak that happens when you go into the idle state on the oculus when using OpenXR. This leak specifically was UI canvases leaking so the more canvases you have in your scene the faster you will leak. We have a fix for this that is currently working its way through release management. One potential work around (I know this is ugly but it should work until the patch is out) is to disable any canvas objects in your scene when the state goes to idle. This can be done with a custom feature fairly easily.

    PS - Just noticed the post above suggesting the same fix :p
     
    AndreasWang likes this.
  5. Deleted User

    Deleted User

    Guest

    I am also having memory leak issues too, but I am using a Vive with the OpenXR plugin going through SteamVR/OpenVR. If I start and stop the play tests enough times, Unity will first warn me that it cannot create a render texture. If I do not respond fast enough to close Unity after that warning, it can crash my computer. I also noticed in task manager that the memory starts increasing every time I play test after a while as well.
     
  6. the_real_apoxol

    the_real_apoxol

    Unity Technologies

    Joined:
    Dec 18, 2020
    Posts:
    467
    This one sounds different, do you see anything in the profiler as to where the memory is going?
     
  7. Deleted User

    Deleted User

    Guest

    Now for some reason I cannot get it to crash after play testing my game I was working on or on a blank empty project. Though restarting the computer before didn't fix it and I did not update anything. But I did see some memory increase on the profiler and task manager. All I did was create a empty 3D Project and installed the OpenXR plugin 1.2.3. Enabled it and fixed what it wanted to be fixed. Added controller profiles and then I just started to hit play button over and over again.
    Here is a pic before I started to start and stop the play tests many times:
    Unity_BlankXR_BeforeTests.png
    Here is after I repeatedly started and stopped the test plays:
    Unity_BlankXR_AfterTests.png
    I don't know if this helps or not. Sorry I couldn't gather any other data and I cannot explain why it is now "working", but I am unsure.
     
  8. Deleted User

    Deleted User

    Guest

    One question, can turning off Virtual Memory or Paging Memory from the system settings cause this issue that I am having? Because I was having other apps crash due to running out of memory, I just remembered that I had this feature turned off because I was concerned about my disks but I forgot to set it back on. Turning the feature back to on through my system settings made the others apps work all of a sudden with no problems. So I am assuming that this should fix it? I am sorry for all of the confusion.
     
    Last edited by a moderator: Jul 12, 2021
  9. the_real_apoxol

    the_real_apoxol

    Unity Technologies

    Joined:
    Dec 18, 2020
    Posts:
    467
    Possible, but not sure. You said it fixed the other apps, did it fix the problem in unity?
     
  10. Deleted User

    Deleted User

    Guest

    Unity seems to be working now at the moment. I even let the VR idling for a while and came back as another test and no problems so far for me. I did multiple play tests with no issues coming up as well. Also VR seems to be a bit faster now too I think. So I guess that setting Virtual Memory or Memory Paging to off for my Windows seems to break some things. I am sorry for the inconvenience because of a system setting.
     
  11. yarsrvenge

    yarsrvenge

    Joined:
    Jun 25, 2019
    Posts:
    87
    Hi,

    It looks like this issue was marked resolved, but the fixes do not include Unity 2020, only 2021? Is there a specific version of 2020 this was fixed in?

    https://issuetracker.unity3d.com/is...oconsoleimplementation-when-exiting-play-mode

     
  12. the_real_apoxol

    the_real_apoxol

    Unity Technologies

    Joined:
    Dec 18, 2020
    Posts:
    467
  13. yarsrvenge

    yarsrvenge

    Joined:
    Jun 25, 2019
    Posts:
    87
    Awesome. Thanks!