TL;DR: Unity implements an OpenXR loader, which (because of something wrong with its xrNegotiateLoaderRuntimeInterface
implementation) is fatally clashing at a very low level with the Windows Mixed Reality OpenXR runtime, resulting in a segfault fatal to the Unity editor.
Hi there,
I'm trying to get a Unity VR sample to run through OpenXR on my Windows Mixed Reality headset (a Samsung Odyssey).
Unity version: 2020.3.12.f1 LTS
Windows Mixed Reality runtime version: 106.2105.21002
WMR API: 1.0.16
Packages:
Mixed Reality OpenXR Plugin 1.0.0
Unity OpenXR Plugin 1.2.3
I'm trying to run the sample demo 'Controller' optionally included with Unity's OpenXR plugin.
A couple of things happen when I try to enter, and then leave play mode in the Unity editor.
On Enter Play mode:
Most things initialize fine, but then:
[XR] [Mixed Reality OpenXR Mesh]: Lifecycle_Initialize.
[XR] [Mixed Reality OpenXR Mesh]: Not supported.
[Subsystems] Failed to initialize subsystem OpenXR Mesh Extension [error: 3]
This error doesn't seem to be fatal, because soon after:
[XR] [20660] [10:18:39.236][Info ] OpenXRSession::HandleSessionStateChangedEvent: state XR_SESSION_STATE_IDLE->XR_SESSION_STATE_READY session=2 time=1160632301200
Suggesting OpenXR properly initialized (on the headset, the blue triangle transition screen opens up to show the four white orbs circling each other--but the orbs just circle indefinitely).
Since I'm getting a black screen in the editor game view and a loading screen in the headset, I click the play button to exit play mode.
The Unity editor then crashes and I get a request to submit a bug report.
The log from the fatal error, when Play mode is toggled:
[MODES] ModeService[default].RefreshMenus
[MODES] ModeService[default].UpdateModeMenus
Error on graphics thread: 1
Stacktrace:
at <unknown> <0xffffffff>
at (wrapper managed-to-native) UnityEngine.XR.OpenXR.OpenXRLoaderBase.Internal_EndSession () [0x00008] in <aa56b155af2d47fbbc2a0265118c4b6c>:0
at UnityEngine.XR.OpenXR.OpenXRLoaderBase.StopInternal () [0x00041] in C:\Users\arcop\git\unity-xr-silence\HMD_Web_Demo_BRP\Library\PackageCache\com.unity.xr.openxr@1.2.3\Runtime\OpenXRLoader.cs:417
at UnityEngine.XR.OpenXR.OpenXRLoaderBase.Stop () [0x0002c] in C:\Users\arcop\git\unity-xr-silence\HMD_Web_Demo_BRP\Library\PackageCache\com.unity.xr.openxr@1.2.3\Runtime\OpenXRLoader.cs:398
at UnityEngine.XR.Management.XRManagerSettings.StopSubsystems () [0x00021] in C:\Users\arcop\git\unity-xr-silence\HMD_Web_Demo_BRP\Library\PackageCache\com.unity.xr.management@4.0.1\Runtime\XRManagerSettings.cs:425
at UnityEngine.XR.Management.XRManagerSettings.DeinitializeLoader () [0x00013] in C:\Users\arcop\git\unity-xr-silence\HMD_Web_Demo_BRP\Library\PackageCache\com.unity.xr.management@4.0.1\Runtime\XRManagerSettings.cs:448
at UnityEngine.XR.Management.XRGeneralSettings.DeInitXRSDK () [0x00021] in C:\Users\arcop\git\unity-xr-silence\HMD_Web_Demo_BRP\Library\PackageCache\com.unity.xr.management@4.0.1\Runtime\XRGeneralSettings.cs:201
at UnityEngine.XR.Management.XRGeneralSettings.Quit () [0x00010] in C:\Users\arcop\git\unity-xr-silence\HMD_Web_Demo_BRP\Library\PackageCache\com.unity.xr.management@4.0.1\Runtime\XRGeneralSettings.cs:128
at UnityEngine.XR.Management.XRGeneralSettings.InternalPlayModeStateChanged (UnityEditor.PlayModeStateChange) [0x00008] in C:\Users\arcop\git\unity-xr-silence\HMD_Web_Demo_BRP\Library\PackageCache\com.unity.xr.management@4.0.1\Runtime\XRGeneralSettings.cs:112
at UnityEditor.XR.Management.XRGeneralSettingsPerBuildTarget.PlayModeStateChanged (UnityEditor.PlayModeStateChange) [0x00033] in C:\Users\arcop\git\unity-xr-silence\HMD_Web_Demo_BRP\Library\PackageCache\com.unity.xr.management@4.0.1\Editor\XRGeneralSettingsPerBuildTarget.cs:83
at (wrapper delegate-invoke) System.Action`1<UnityEditor.PlayModeStateChange>.invoke_void_T (UnityEditor.PlayModeStateChange) [0x00070] in <695d1cc93cca45069c528c15c9fdd749>:0
at UnityEditor.EditorApplication.Internal_PlayModeStateChanged (UnityEditor.PlayModeStateChange) [0x0001e] in <dc14d30a5e0540ee9311ed6df63d9074>:0
at (wrapper runtime-invoke) <Module>.runtime_invoke_void_int (object,intptr,intptr,intptr) [0x00022] in <dc14d30a5e0540ee9311ed6df63d9074>:0
at <unknown> <0xffffffff>
at (wrapper managed-to-native) UnityEditor.EditorApplication.set_isPlaying (bool) [0x00007] in <dc14d30a5e0540ee9311ed6df63d9074>:0
at UnityEditor.EditorApplication.TogglePlaying () [0x00009] in <dc14d30a5e0540ee9311ed6df63d9074>:0
at UnityEditor.UnityMainToolbar.DoPlayButtons (bool) [0x000ba] in <5f5866ec908d4054a9597064f39dbbac>:0
The editor tries to recover, but ends up hitting a segmentation fault, and crashes out completely:
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries
used by your application.
Received signal SIGSEGV
Stack trace:
0x00007ffbaeed2640 (WinXrRuntime) xrNegotiateLoaderRuntimeInterface
0x00007ffbaeed1f4d (WinXrRuntime) xrNegotiateLoaderRuntimeInterface
0x00007ffbaee9bacb (WinXrRuntime) xrNegotiateLoaderRuntimeInterface
0x00007ffbaee8b1a9 (WinXrRuntime) xrNegotiateLoaderRuntimeInterface
0x00007ffbaeef338f (WinXrRuntime) xrNegotiateLoaderRuntimeInterface
0x00007ffbaee5597d (WinXrRuntime) xrNegotiateLoaderRuntimeInterface
0x00007ffbaa191a86 (UnityOpenXR) session_EndSession
0x000001ebc7bc9251 (Mono JIT Code) (wrapper managed-to-native) UnityEngine.XR.OpenXR.OpenXRLoaderBase:Internal_EndSession ()
0x000001ebc7bc8c2b (Mono JIT Code) [OpenXRLoader.cs:418] UnityEngine.XR.OpenXR.OpenXRLoaderBase:StopInternal ()
0x000001ebc7bc89b3 (Mono JIT Code) [OpenXRLoader.cs:400] UnityEngine.XR.OpenXR.OpenXRLoaderBase:Stop ()
0x000001ebc7bc891c (Mono JIT Code) [XRManagerSettings.cs:427] UnityEngine.XR.Management.XRManagerSettings:StopSubsystems ()
0x000001ebc7bc881b (Mono JIT Code) [XRManagerSettings.cs:449] UnityEngine.XR.Management.XRManagerSettings:DeinitializeLoader ()
0x000001ebc7bc877b (Mono JIT Code) [XRGeneralSettings.cs:202] UnityEngine.XR.Management.XRGeneralSettings:DeInitXRSDK ()
0x000001ebc7bc86c3 (Mono JIT Code) [XRGeneralSettings.cs:129] UnityEngine.XR.Management.XRGeneralSettings:Quit ()
0x000001ec278793ab (Mono JIT Code) [XRGeneralSettings.cs:119] UnityEngine.XR.Management.XRGeneralSettings:InternalPlayModeStateChanged (UnityEditor.PlayModeStateChange)
0x000001ec27879333 (Mono JIT Code) [XRGeneralSettingsPerBuildTarget.cs:84] UnityEditor.XR.Management.XRGeneralSettingsPerBuildTarget:PlayModeStateChanged (UnityEditor.PlayModeStateChange)
0x000001ec27864cd5 (Mono JIT Code) (wrapper delegate-invoke) System.Action`1<UnityEditor.PlayModeStateChange>:invoke_void_T (UnityEditor.PlayModeStateChange)
0x000001ec27864c04 (Mono JIT Code) UnityEditor.EditorApplication:Internal_PlayModeStateChanged (UnityEditor.PlayModeStateChange)
My hunch is that because the Windows OpenXR runtime is not properly initializing, when the Player makes a call to take back control from OpenXR, an invalid / null session is tried to be terminated, resulting in the segfault.
xrNegotiateLoaderRuntimeInterface
fails several times before the actual fault.
From the OpenXR SDK docs:
Loader/Runtime Interface Negotiation
The OpenXR symbols exported by a runtime must not clash with the loader’s exported OpenXR symbols. Because of this, all runtimes must export only the following command with beginning with the xr prefix. This command is not a part of the OpenXR API itself, only a private interface between the loader and runtimes for version 1 and higher interfaces. In order to negotiate the loader/runtime interface version, the runtime must implement the xrNegotiateLoaderRuntimeInterface
function (or a renamed version of this function identified in the manifest file).
https://github.com/KhronosGroup/OpenXR-SDK-Source/blob/master/specification/loader/runtime.adoc
More on loaders vs runtimes:
https://github.com/KhronosGroup/OpenXR-SDK-Source/blob/master/specification/loader/overview.adoc
I may be understanding this wrong, but it seems that:
Unity implements an OpenXR loader, which (because of something wrong with its xrNegotiateLoaderRuntimeInterface
implementation) is fatally clashing at a very low level with the Windows Mixed Reality OpenXR runtime, resulting in a segfault fatal to the Unity editor.
With that said, I should also get in touch with the Unity community, but if you have any pointers here I'm happy to hear them :)
Thank you!