Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug [OpenXR] [Windows] Segmentation fault crashes Unity editor on exit play mode

Discussion in 'VR' started by alex_dossamer, Jul 2, 2021.

  1. alex_dossamer

    alex_dossamer

    Joined:
    Jun 19, 2018
    Posts:
    25
    TL;DR: Unity implements an OpenXR loader, which (because of something wrong with its `xrNegotiateLoaderRuntimeInterface` implementation) is clashing at a very low level with the Windows Mixed Reality OpenXR runtime, resulting in a segfault fatal to the Unity editor.

    (Crosspost from: https://docs.microsoft.com/en-us/an...enxr-unity-segmentation-fault-on-exiting.html)

    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.

    Working on a tight deadline, and this is a really, really disappointing regression.

    Thank you!
     

    Attached Files:

  2. the_real_apoxol

    the_real_apoxol

    Unity Technologies

    Joined:
    Dec 18, 2020
    Posts:
    467
    Ignore my last question if you saw it, I read the log wrong.
     
  3. the_real_apoxol

    the_real_apoxol

    Unity Technologies

    Joined:
    Dec 18, 2020
    Posts:
    467
    I would start by first disabling any custom features you have enabled in the openxr settings and only use the interaction profile for your controller. If that works then start enabling features until it fails.
     
  4. alex_dossamer

    alex_dossamer

    Joined:
    Jun 19, 2018
    Posts:
    25
    Hi @the_real_apoxol ,

    Folks over at Microsoft forums had similar feedback:
    https://docs.microsoft.com/en-us/an...exiting.html?childToView=470319#answer-470319

    I made a fresh project just with the OpenXR plugin, no windows XR / WMR openxr runtime packages.

    New kind of error, when the graphics thread crashes:


    [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


    See attached for full log; microsoft forum post has graphics driver specs listed.

    Thank you!
     

    Attached Files:

  5. the_real_apoxol

    the_real_apoxol

    Unity Technologies

    Joined:
    Dec 18, 2020
    Posts:
    467

    Can you submit a bug with `Help -> Report a bug` with that sample project? If you do please post the issue number here so we can take a look at it sooner. For sure that `Error on graphics thread` is the problem as once that happens the gfx thread is shut down.
     
  6. alex_dossamer

    alex_dossamer

    Joined:
    Jun 19, 2018
    Posts:
    25
    Hi again, submitted a fresh crash report:
    https://fogbugz.unity3d.com/default.asp?1349875_4v73becuc85kinha

    Case 1349875

    Thank you!
     
    the_real_apoxol likes this.
  7. alex_dossamer

    alex_dossamer

    Joined:
    Jun 19, 2018
    Posts:
    25
    Hi @the_real_apoxol , any updates on the issue? It's a critical blocker for our current project; there aren't really any sustainable long-term workarounds. (At the moment we're using a deprecated MRTK plugin / runtime from 2019 but we really need to get onto OpenXR as soon as possible, because our client's target hardware isn't from Microsoft.) Thank you!
     
  8. the_real_apoxol

    the_real_apoxol

    Unity Technologies

    Joined:
    Dec 18, 2020
    Posts:
    467
    We have someone looking at it today. We have not been able to reproduce it yet with the project you submitted. If we are unable to reproduce it today we will make you a preview build of 1.2.4 that has some extra logging in it for when this happens so we can hopefully figure out what is going on.
     
    alex_dossamer likes this.