Skip to content

Commit

Permalink
[OpenXR] Fixes crashes when no device is present (stride3d#2121)
Browse files Browse the repository at this point in the history
The essential part here is that `OpenXRHmd.CanInitialize` will now return false if no device is present. This ensures that the `VRDeviceSystem` sets up a dummy device which in turn prevents many parts from crashing.

To truly know whether or not an actual device is connected we first need to establish contact with the OpenXR runtime. Therefor code has been moved around a bit to be able to call various parts individually.
Tested on two machines, one without any VR related things installed and another one with an actual device.

This commit also contains a bunch of code cleanups:
- Enables C# nullable feature on OpenXR files
- Adds null checks to various places
- Disposes XR API after shutting down the device
- Makes various fields and methods private
- Moves initialization code to a `OpenXRUtils` class to make dependencies more visible
- Turns OpenXRInput into a normal class holding a reference to the device
- Turns `CheckResult` into a extension method and simplifies its usage by letting C# infer the called method
- Introduced `OpenXRException` exception class carrying the inferred method and XR error code
  • Loading branch information
azeno committed Jan 26, 2024
1 parent 80693e7 commit d72aef5
Show file tree
Hide file tree
Showing 6 changed files with 536 additions and 429 deletions.
19 changes: 19 additions & 0 deletions sources/engine/Stride.VirtualReality/OpenXR/OpenXRException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using Silk.NET.OpenXR;

namespace Stride.VirtualReality
{
internal sealed class OpenXRException : Exception
{
public OpenXRException(Result result, string methodName)
: base($"{methodName} returned {result}")
{
Result = result;
MethodName = methodName;
}

public Result Result { get; }

public string MethodName { get; }
}
}
Loading

0 comments on commit d72aef5

Please sign in to comment.