question

AlexanderRuppCoppi-2965 avatar image
0 Votes"
AlexanderRuppCoppi-2965 asked YinLiOLIVER-8642 edited

Windows OpenXR + Unity segmentation fault on exiting play mode

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!

hololens-development
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

If you're building VR applications on Windows PC, the Mixed Reality OpenXR plugin is not necessarily required. Could you remove this plugin and try it again?

0 Votes 0 ·

ISorry for the late response! I'll give that a shot, thank you.

0 Votes 0 ·
YinLiOLIVER-8642 avatar image
0 Votes"
YinLiOLIVER-8642 answered AlexanderRuppCoppi-2965 commented

@AlexanderRuppCoppi-2965 , There are a few issues in your report:

  1. The SIGSEGV log you added at the end of the report is because you don't have symbols for the dll. This xrNegotiateLoaderRuntimeInterface is the first exported function in the dll and therefore every "crash stack" is named as this function plus an offset. It doesn't represent the crash is related to this function.

  2. This trace "(UnityOpenXR) session_EndSession" indicate the crash happens when the session is shutting down. We have to see the heap dump to diagnose further on this issue. Could you please open a "Feedback hub bug" using "Mixed Reality" -> "Device" category? then send us your report Id:
    112326-image.png

  3. The "missing mesh subsystem" is correct message because the "mesh subsystem" is indeed not supported by VR system. It shouldn't affect what you are seeing.

  4. "show the four white orbs circling each other--but the orbs just circle indefinitely" This is not correct. Can you elaborate how run your app? Do you click the "play" button in Unity editor? or do you build and run the application as win32 app? or do you build a UWP app? Attaching a Unity trace will be helpful for us to help you.

  5. Building XR experience in unity can be sensitive to your project settings. It can be helpful if you following the instruction on the documentation:
    https://docs.microsoft.com/en-us/windows/mixed-reality/develop/unity/xr-project-setup?tabs=openxr
    Or you can also clone our public sample and see if you can get the "BasicSample" app working first.
    https://github.com/microsoft/OpenXR-Unity-MixedReality-Samples#welcome

  6. As @HernandoRen-MSFT said, if you are building VR app using the Samsung Odyssey headset and targeting at "stand alone" platform (win32 exe app), then you don't need to include the "Mixed Reality features" in your project. But if you are using HP reverb G2 headset, or building UWP app then you'd better include it. From what you said, your project setting probably should be like this:
    112382-image.png




image.png (13.0 KiB)
image.png (37.9 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks so much for the detailed response! Am working through your suggestions now, will post an update soon.

0 Votes 0 ·
AlexanderRuppCoppi-2965 avatar image
0 Votes"
AlexanderRuppCoppi-2965 answered

Hello! I made a fresh project, and disabled everything except for OpenXR (no custom windows XR packages are in the project).

I have a new error (see the log):

When the graphics thread crashes, the same error happens over and over, until the OpenXR runtime gives up and shuts down.

[XR] [OpenXR Input]: Requested application space not available, falling back to local space
Error on graphics thread: 1
[XR] [OpenXR Input]: Application space recovered
[XR] [OpenXR Input]: Requested application space not available, falling back to local space
[XR] [OpenXR Input]: Application space recovered
[XR] [OpenXR Input]: Requested application space not available, falling back to local space
[XR] [OpenXR Input]: Application space recovered


Full log is attached.

Current settings:
113410-image.png


113444-image.png

I also updated the Windows Mixed Reality runtime to the preview release.
113541-image.png

And got the latest graphics driver for my pc.
113469-image.png


113496-editorcrashlog.txt



image.png (47.6 KiB)
image.png (65.8 KiB)
image.png (61.5 KiB)
image.png (172.1 KiB)
editorcrashlog.txt (361.0 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

YinLiOLIVER-8642 avatar image
1 Vote"
YinLiOLIVER-8642 answered AlexanderRuppCoppi-1695 commented

Thanks for building simpler project to test this crash. I read your new log, and i'm still puzzled on this crash.

Unfortunately, unity's trace is cut too early due to the app fail to render frames. The "READY" state is a signal for unity to start frame loop but it seems never started due to lack of proper tracking: "Requested application space not available, falling back to local space". This is not fatal, but it didn't reach to the code for unity to dump diagnoses for runtime details. So we probably have to find other ways to find details.

Since you are using an AMD graphics card, i suspect there's something abnormal that we typically didn't see in our dev teams.


Here's my suggestion:

  1. Try to download this "dev tools" app from the Store, and run the "Demo Scene" here to see if your device is properly setup. Make sure you can see the demo scene in your headset and the headset is properly tracked through openxr here. And also try to click the "stop demo scene" button, to test the similar scenario to quit the session and closing down application. This demo scene is not a unity app. We can isolate if this is a problem below the runtime or inside unity.

  2. I'd like to get your dxdiag.txt log if it's ok for you to share.

  3. I think it might be good for you to give us a runtime trace for us to understand what's going on. This involves running the windows tracing service in admin prompt with a configuration for openxr runtime. I can share the details to you if you'd like to give this a try.

  4. There should be a "dmp" file for the crash in this folder "%LOCALAPPDATA%\Temp\Unity\Editor\Crashes". Could you zip this dump file and send it to us? Not sure if it helps, we can at least understand the crash stack with our symbol files.


· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hello! I'm so sorry I missed this--notifications seem to be muted for some reason. I've been in touch quite a bit with one of the OpenXR devs over at Unity, and he actually gave me access to a preview OpenXR package build with a verbose logger. We found a new exception (truncated):
```
==== OpenXR Exception Thrown ====
[XR] [11808] [15:26:44.207][Info ] ==== Std Exception Thrown ====
[XR] [11808] [15:26:44.207][Info ]
[XR] [11808] [15:26:44.207][Info ] Function: Display_Initialize::<lambda_c64f573b7e9ec0777a0cd5afe3312cb6>::operator ()
[XR] [11808] [15:26:44.207][Info ] Message: XrResult failure [XR_ERROR_RUNTIME_FAILURE]
[XR] [11808] [15:26:44.207][Info ] Origin: xrEndFrame(m_Ctx.session->GetSession(), &m_FrameEndInfo)
[XR] [11808] [15:26:44.207][Info ] Source: D:\repos\xr.sdk.openxr.alt\NativePlugin/Source/unity_display.cpp:327
```
And the Unity dev told me that XR_ERROR_RUNTIME_FAILURE means the issue is something with WMR OpenXR.

Just today I ran the OpenXR dev tools demo scene, and it rendered fine (floating asteroids, purple mountains, and a blue sky). So Microsoft-provided OpenXR stuff seems to do alright but there's some funkiness when 3rd parties call into the API.

Will work on steps 2, 3, and 4 you suggested shortly! Thanks :)

0 Votes 0 ·

Hello again! Please find linked the DxDiag and a zip with the DMP file. Happy to try the admin trace too, if you'd be willing to write up specific instructions. (The uploader here was being finnicky / didn't support .ZIP) Thank you!

DxDiag
https://drive.google.com/file/d/1zKvI141BoGgmaJeOZt9_0uMIVQmEWEBi/view?usp=sharing

DMP zip
https://drive.google.com/file/d/1vu9eS7IR3fTZuEpmnv2gEyWTa6WnlYbm/view?usp=sharing

0 Votes 0 ·
YinLiOLIVER-8642 avatar image
0 Votes"
YinLiOLIVER-8642 answered YinLiOLIVER-8642 edited

@AlexanderRuppCoppi-1695 Sorry for late reply. We've been making fixes in this area related to the "RUNTIME_FAILURE" at xrEndFrame(). It's a delicate problem on hybrid GPU and we don't have full confident it fixed your issue. We recently published a preview runtime 108.2109.10009. Please use the "openxr dev tools" to turn on "Preview runtime" and see if this solved the crashing issue you were seeing.

Thanks

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.