microsoft / OpenXR-MixedReality

OpenXR samples and preview headers for HoloLens and Windows Mixed Reality developers familiar with Visual Studio
https://aka.ms/openxr
MIT License
335 stars 95 forks source link

BasicXRApp exits when VR Device goes to sleep #112

Closed Findus79 closed 1 year ago

Findus79 commented 1 year ago

When running BasicXRApp and the VR Device goes to sleep, the application exits. Is there a sample where devices going to sleep and waking up again are properly handled?

mbucchia-msft commented 1 year ago

Hello,

Today, you can detect that the headset is going to sleep based on receiving the XR_SESSION_STATE_EXITING. This is because handling of the headset going to sleep is similar to the headset being un-plugged. In the BasicXrApp, this event is causing the application to terminate its main loop and exit, hence the behavior you are seeing.

After handling this event, you have the choice to continue running your app in the background and/or in 2D mode rather than exiting. You can then offer to the user the ability to resume the VR experience, for example exposing a button in a 2D window to re-enter VR. This button shall create and begin a new XrSession, which will automatically wake up the headset.

You may look at the SampleSceneWin32 sample. which has a 2D window offering Enter/Exit VR. Upon the headset going to sleep, that 2D window stays open, and clicking Enter VR will allow the user to re-enter VR either before waking up the headset (which will wake it up) or after they woke up the headset manually.

Findus79 commented 1 year ago

Thank you, that helps a lot :)