cancel
Showing results for 
Search instead for 
Did you mean: 

Here's a script for preventing editor crashes when reloading while in play mode

Weitin
Level 4
OVR crashes the Unity Editor when saving a script while in play mode. I'm not sure if the crash occurs exactly before or after reloading.
Here's a script that detects when Unity will reload, removes OVR, and stops play mode. I haven't successfully restarted the play mode, but I'm happy to have it not crash anymore. Using Oculus Integrations 1.41 on Unity 2019.1.2f1, targeting Quest headsets.

#if UNITY_EDITOR
using UnityEngine;
using UnityEditor;

[InitializeOnLoad]
public static class EditorOVRCrashCatcher
{

private const bool DestroyRig = true;
private const bool DestroyAvatar = true;

// register an event handler when the class is initialized
static EditorOVRCrashCatcher()
{
AssemblyReloadEvents.beforeAssemblyReload += DestroyOVR;
}

private static void DestroyOVR()
{
if (!EditorApplication.isPlaying)
return;

//Debug.Log("Before Assembly Reload");
GameObject rig = Object.FindObjectOfType<OVRCameraRig>()?.transform.root.gameObject;
GameObject avatar = Object.FindObjectOfType<OvrAvatarSDKManager>()?.gameObject;
if (DestroyRig && rig)
{
Debug.Log("Destroying OVR Instance");
Object.Destroy(rig);
}
if (DestroyAvatar && avatar)
{
Debug.Log("Destroying OVR Instance");
Object.Destroy(avatar); //Throws errors once ovr is destroyed.
}
EditorApplication.ExitPlaymode();
//Haven't figured out a way to restart play mode so I'll just stop here.
}
}
#endif

Snippets from crash log:
libovravatar.DLL caused an Access Violation (0xc0000005)
  in module libovravatar.DLL at 0033:e7450b10.

Stack Trace of Crashed Thread 9312:
0x00007FFCE7450B10 (libovravatar) ovrAvatarSpecification_GetAvatarSpecificationUri
0x00000228352ED51A (Assembly-CSharp) Oculus.Avatar.CAPI.ovrAvatarPose_GetLeftControllerComponent_Native()
0x00000228352ECFCB (Assembly-CSharp) Oculus.Avatar.CAPI.ovrAvatarPose_GetLeftControllerComponent()
0x00000228352ECBC3 (Assembly-CSharp) OvrAvatarTouchController.Update()
0x000002283D791548 (mscorlib) System.Object.runtime_invoke_void__this__()
0x00007FFCFDD8BBCB (mono-2.0-bdwgc) mono_get_runtime_build_info
0x00007FFCFDD12252 (mono-2.0-bdwgc) mono_perfcounters_init
0x00007FFCFDD1B25F (mono-2.0-bdwgc) mono_runtime_invoke
0 REPLIES 0