I am creating a VR app for Android and iOS that is basically a menu system and 360 degree movie player for a series of short films.
I want the user to be able to choose to either use Google Cardboard or or just to view the app in monoscopic by rotating the phone and using the gyro data. The current problem is that if I try to load the cardboard device at runtime on my android phone the app crashes around 3/5 times. As far as I am aware there seems to be no difference to how I interact with the app when it crashes or works.
When the app crashes the screen just goes black and the app is closed by the phone and I get a pop up saying the app has stopped and I can click to “close app”.
I am testing on a Nexus 6P using the native cardboard functionality in the beta 5.6 unity. I’m not using the GVR plugin but I did try importing it and building my app and it didn’t help.
To do this I have set up the Player settings to enable virtual reality and added “None” and “Cardboard” to the virtual reality SDK’s so that the app loads with virtual reality disabled and I can enable it based on the users first choice when the app starts.
I am using the coroutine written below to load the device and then set the vr settings to enabled
I am calling the coroutine from the start function in the same script to set the device to “None” and in a function fired on a button press to set the device to “cardboard”
void Start () {
StartCoroutine(SetVRDevice("None", false));
//rest of start function stuff
}
StartCoroutine(SetVRDevice("cardboard", true));
I have tried building the app from 5.6.0b10, 5.6.0b11 and 5.6.0f1 and the all end in the same problem: the phone crashes just over half the time.
I wasn’t previously setting the VR device to none in the start function but doing this has seemed to decrease the frequency that the app crashes so I have kept it in for now.
I have searched the forums on here and have found a couple of people trying to do the same thing but the fixes posted on those forums haven’t fixed my problem. I can post more information if necessary but I’m not sure what is relevant.
Has anyone else came across similar issues? Any recommendations on what I could try?
03-22 14:37:33.658 2202 2231 E Unity : [EGL] Failed to create window surface: EGL_BAD_ALLOC: EGL failed to allocate resources for the requested operation.
03-22 14:37:33.658 2202 2231 E Unity :
03-22 14:37:33.658 2202 2231 E Unity : (Filename: ./Runtime/GfxDevice/egl/WindowContextEGL.cpp Line: 141)
03-22 14:37:33.658 2202 2231 E Unity :
03-22 14:37:33.658 2202 2231 I Unity : Skipped rendering frame because GfxDevice is in invalid state (device lost)
03-22 14:37:33.658 2202 2231 I Unity :
03-22 14:37:33.658 2202 2231 I Unity : (Filename: Line: 772)
03-22 14:37:33.658 2202 2231 I Unity :
03-22 14:37:33.819 2202 2231 I Unity : Skipped rendering frame because GfxDevice is in invalid state (device lost)
03-22 14:37:33.819 2202 2231 I Unity :
03-22 14:37:33.819 2202 2231 I Unity : (Filename: Line: 772)
03-22 14:37:33.819 2202 2231 I Unity :
Not sure if this is helpful as I can’t make sense of it. This is the log that is printed starting when I click the button that should switch the VR mode to cardboard.
Yes, according to the docs you always need to wait at least one Update/Frame between loading the device and enabling vrsettings. The check for device loaded and yield if not seems like a good way to catch a case where loading the device may for some reason take longer than one frame. Usually when I do this I actually do the switching in a MonoBehaviour::Update where I can make sure that I don’t enable vr settings until the next Update after the load device is called.
When you say it’s back, what exactly are you seeing? Do you have logcat output showing a crash log? Are you doing the correct wait a frame procedure as outlined above?
i’ve tested in on devices android api 21 to 24 but my primary device is a note 3 samsung
the error is produced in 2017.2 and 2017.3 but the error doesn’t seam to pop up in 2018.1.b9 but will still crash on vr mode
in the sdk manager
i also have all the android build tools installed and sdk from api 21 to api 27
it doesn’t seam to be project related because another project of mine got affected
error Could not recreate VR window because GfxDevice is in an invalid state
i even tried adding time delays
IEnumerator testco()
{
yield return new WaitForSeconds(3);
UnityEngine.XR.XRSettings.enabled = true;
yield return new WaitForSeconds(3);
Screen.orientation = ScreenOrientation.LandscapeLeft;
yield return new WaitForSeconds(3);
UnityEngine.XR.XRSettings.LoadDeviceByName("cardboard");
yield return new WaitForSeconds(3);
UnityEngine.XR.XRSettings.enabled = true;
}
after testing i finally got it working again but it doesn’t work with .net 4.6 only 3.5
i was able to fix it by adding “NONE” not just the cardboard on 2.1.1f . but it dosn’t work with the current beta 2018.
i assume the cause of the problem is when i tried to update my unity version
This will ensure that your app is in 2D mode prior to attempting to change the screen orientation. This might be why you’re seeing correct behavior when adding “none” to your SDK list.