Showing results for 
Search instead for 
Did you mean: 

VR+nonVR app and headset detection best practices

Level 2

I'm developing an app that runs in both non-VR and VR.  I want the user to be able to be using the app outside of VR, then get their headset out, put it on, (in the case of the Quest 2, connect to AirLink), and the app detects the headset and seamlessly transitions to VR.  If they take it off, they're back in non-VR.


In the proprietary Oculus SDK, I can do this in my app's event loop by calling 

ovr_GetHmdDesc(), then creating a session, and then checking HmdMounted.  This is polling based, but is fine because the functions return quite quickly (in the 1ms range, which means I can call it a few times a second and still be quite snappy about detecting VR).
I'm trying to do the equivalent in OpenXR.  I think this is meant to be done by:
1. xrGetSystem() and check that I got a valid system ID.
2. xrCreateSession().
3. Service the event queue via xrPollEvent, looking for XR_SESSION_STATE_READY event.
4. xrBeginSession().
I've got this all working and it's nice and snappy with AirLink connected.  However, if I disconnect AirLink, then perform step 1, the call to xrGetSystem() takes 0.5 seconds.  How can my app gracefully handle whatever state the user's XR system is in, including this no AirLink connected state, without the 0.5 second blocking call?  I want to avoid the user having to click an "enable VR" button.  I thought about polling xrGetSystem() in another thread, but I'd rather not tie up an entire thread just to do VR state detection.
One thing I've noticed is in Task Manager, the calls to xrGetSystem() don't seem to busy the CPU, which suggests that it is sleep-waiting on something.  Any help on this is appreciated!

Oculus Staff

Thanks for the report @cubeleo - this is easy to replicate and I'll make sure that a fix for this gets pushed out in upcoming release (targeting Oculus PC release v41).


Level 2

Excellent!  Thanks very much for the replication effort and upcoming fix.  For now, I've spawned a thread just for repeated polling of xrGetSystem().