Search Unity

Crash in android when changing VRSettings.enabled

Discussion in 'AR/VR (XR) Discussion' started by JoseEDC, Jul 11, 2017.

  1. JoseEDC

    JoseEDC

    Joined:
    May 15, 2017
    Posts:
    8
    Hi there.
    I'm currently working in an application for android which should change at runtime from vr mode enabled to disabled to allow the user using the device with cardboard for 3d effect or without cardboard for a kind of magic window.

    So basicly I have a function like this:

    Code (CSharp):
    1. public IEnumerator LoadDevice(string newDevice, bool vrModeActive)
    2.     {      
    3.         if (!VRSettings.loadedDeviceName.Equals(newDevice))
    4.         {
    5.             yield return new WaitForSeconds (1f);
    6.             VRSettings.LoadDeviceByName(newDevice);
    7.             yield return new WaitForSeconds (1f);
    8.         }
    9.         VRSettings.enabled = vrModeActive;
    10.  
    11.         foreach (Camera item in m_allCameras)
    12.         {
    13.  
    14.             item.ResetAspect();
    15.         }    
    16.     }

    It should allow me to change current device and Vr mode status for every possible application behaviour:
    --Working with Gyros and stereo view for cardboard setting loadedDevice = "cardboard" and VRSettings.enabled = true.

    --Working with Gyros but mono view for magic window setting loadedDevice = "cardboard" and VRSettings.enabled = false (in this mode I got rotation from InputTracking.GetLocalRotation(VRNode.CenterEye);

    --Working with no Gyros and mono view for touchscreen input setting loadedDevice = "None" and VRSettings.enabled = false.

    Application starts with a call to LoadDevice("cardboard", false) so gyros are enabled and working but screen is in mono mode.

    The problem was, at first, that the application crashed every time I tried to change the device or VRSettings.enabled status (I had no WaitForSecond call).

    After adding WaitForSecond calls it seems to work sligthtly better and I can even change mode a few times but after a couple of changes it crashes again. I got this from logcat when crashing:

    Code (CSharp):
    1. [EGL] Failed to create window surface: EGL_BAD_ALLOC: EGL failed to allocate resources for the requested operation.
    2. 07-11 16:37:27.558 20768 20784 E Unity   :
    3. 07-11 16:37:27.558 20768 20784 E Unity   : (Filename: ./Runtime/GfxDevice/egl/WindowContextEGL.cpp Line: 141)
    4. 07-11 16:37:27.558 20768 20784 E Unity   :
    5. 07-11 16:37:27.558 20768 20784 I Unity   : Skipped rendering frame because GfxDevice is in invalid state (device lost)
    Anybody knows why is this happening and how it can be fixed?
     
  2. joejo

    joejo

    Unity Technologies

    Joined:
    May 26, 2016
    Posts:
    958
    I am not sure what version you are using, but if you can please upgrade to 5.6.2p2 as there is a GVR texture deletion issue that was resolved in that release that directly impacts this scenario.

    As for the wait, it is important that you give at least one frame between calling LoadDeviceByName and setting VRSettings.enabled. I am not sure the documentation is clear on that and that is something that we are looking to resolve soon.
     
  3. joejo

    joejo

    Unity Technologies

    Joined:
    May 26, 2016
    Posts:
    958
    There IS a leak in GVR that you may run into as well over a long run of transitioning in/out of VR many times so this won't be 100% resolved with 5.6.2p2, but it should be MUCH better. The leak will be fixed by Google in an upcoming release of VrCore that should be shipped directly to devices.
     
  4. JoseEDC

    JoseEDC

    Joined:
    May 15, 2017
    Posts:
    8
    I was in 5.6.2f1. Just updated to 5.6.2p2 and after a few tries it seems to be changing modes steady as a rock now. Thank you so much, joejo, you saved my evening :)