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:
public IEnumerator LoadDevice(string newDevice, bool vrModeActive)
{
if (!VRSettings.loadedDeviceName.Equals(newDevice))
{
yield return new WaitForSeconds (1f);
VRSettings.LoadDeviceByName(newDevice);
yield return new WaitForSeconds (1f);
}
VRSettings.enabled = vrModeActive;
foreach (Camera item in m_allCameras)
{
item.ResetAspect();
}
}
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:
[EGL] Failed to create window surface: EGL_BAD_ALLOC: EGL failed to allocate resources for the requested operation.
07-11 16:37:27.558 20768 20784 E Unity :
07-11 16:37:27.558 20768 20784 E Unity : (Filename: ./Runtime/GfxDevice/egl/WindowContextEGL.cpp Line: 141)
07-11 16:37:27.558 20768 20784 E Unity :
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?