Search Unity

VRSettings.LoadDeviceByName() is creating a memory leak on Android.

Discussion in 'AR/VR (XR) Discussion' started by Liinnkk, May 17, 2017.

  1. Liinnkk

    Liinnkk

    Joined:
    Mar 19, 2016
    Posts:
    8
    I'm using this method (LoadDeviceByName) in my game followed by VRSettings.enabled = true to start VR at runtime. But when I try this approach, the GfxDriver (only the GfxDriver!) starts to grow every frame (in 20 seconds, memory allocated by the GfxDriver jumps from 40MB to 160MB or even 200MB+). The game can't even stand for a minute and it crashes. Here's my code:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.VR;
    5.  
    6. public class VRLoaderScript : MonoBehaviour {
    7.  
    8.     void Start() {
    9.         StartCoroutine(LoadDevice("Cardboard"));
    10.     }
    11.  
    12.     IEnumerator LoadDevice(string newDevice) {
    13.         VRSettings.LoadDeviceByName(newDevice);
    14.         yield return null;
    15.         VRSettings.enabled = true;
    16.     }
    17. }
    18.  
    For tracking purposes, I configured the project to start with the Cardboard enabled. So even when I comment the "VRSettings.LoadDeviceByName(newDevice);" line, the Cardboard still work. This way I could discover that when I comment this line, memory leak completely stops, even if the VR still working. I can't understand what's happenning, someone have a clue?

    I've noticed some strange behaviors while profiling the memory leak in CPU usage:
    1. Canvas.BuildBatch > ScheduleGeometryJobs becomes quite unstable, jumping to 80 ms periodically. This doesn't happens if I comment that line of code.
    2. SplashScreenRender often jumps from 0 to ~50 ms. And same as ScheduleGeometryJobs, it doesn't happens if the line is commented.
    Some profiler pics when the code is uncommented:







     
    Last edited: May 17, 2017
  2. MaskedMouse

    MaskedMouse

    Joined:
    Jul 8, 2014
    Posts:
    1,092
    the device name is cardboard with a lowercase c btw (even though it works it's said to be a lowercase c).
    What version of Unity are you using?
    Can you replicate it with an empty scene and just GVR?
    To me the problem lies more at the canvas than GVR, but it is indeed strange that if you enable GVR that the leak starts.
    I haven't seen it do that yet though.
     
  3. joejo

    joejo

    Unity Technologies

    Joined:
    May 26, 2016
    Posts:
    958
    What version of Unity are you using?
     
  4. Liinnkk

    Liinnkk

    Joined:
    Mar 19, 2016
    Posts:
    8
    Unity 5.6

    I'll try to replicate it using an empty scene and I'll tell you the results as soon as possible. I have multiple canvas in my scene with TextMeshPro texts in it, but I couldn't see any impact when I deactivated them (the canvases).

    @Topic
    I updated the post with the SplashScreenRender graph view, since the ScheduleGeometryJobs image was accidentally uploaded twice, my bad.
     
  5. joejo

    joejo

    Unity Technologies

    Joined:
    May 26, 2016
    Posts:
    958
    5.6 is using the 1.2 version of the Google NDK which has a known leak when going in and out of VR. Can you try using latest beta of 2017.1 which uses the 1.4 version and see if you still have the memory leak?
     
    Liinnkk likes this.
  6. Liinnkk

    Liinnkk

    Joined:
    Mar 19, 2016
    Posts:
    8
    I'm trying to reimport my project to Unity 2017.1, but when I click continue nothing happens. I tried with other two another projects and the reimport was sucessful. My project still opening in 5.6. I tried to delete a Temp folder with UnityLock in my folder but it doesn't make any difference. Do you know what can be happening?

    EDIT: Solved this problem deleting Library folder from my project. Upgrading from 5.6 to 2017.1 solved my problem. Memory leak is no more. Thanks!
     
    Last edited: May 18, 2017