Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OpenXR] Fixes crashes when no device is present #2121

Merged
merged 1 commit into from
Jan 26, 2024

Conversation

azeno
Copy link
Collaborator

@azeno azeno commented Jan 23, 2024

PR Details

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.

Description

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 an extension method and simplifies its usage by letting C# infer the called method
  • Introduces OpenXRException exception class carrying the inferred method and XR error code

Related Issue

Probably causes conflicts with #2119 which we would offer to fix.

Motivation and Context

The system shouldn't crash when no VR device is present.

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My change requires a change to the documentation.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • I have built and run the editor to try this change out.
  • I did run a VR patch in vvvv with two machines, one having a device, and the other which doesn't

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
@Eideren Eideren merged commit d72aef5 into stride3d:master Jan 26, 2024
2 checks passed
@Eideren
Copy link
Collaborator

Eideren commented Jan 26, 2024

Looks good @azeno - thanks again :)
We'll continue over in #2119

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants