Can't get OpenXR to initialize. Tutorial works

Hi. So I’ve been trying to get OpenXR to work with a GLFW window. I tried all the repos online, none of them work. However, chapter 3 of the Khronos tutorial works.

So I copied the code from create instance, into another project that just used the OpenXR-SDK-main i downloaded off github.

I get the error xrCreateInstance failed -4
I can’t find anything online or here about error -4

The exact same code works in the chapter 3 tutorial.

I’ve compared the two projects, and besides using their own GFX library in the Khronos tutorials, they are exactly the same.

Thanks in advance
Odin

Return codes are actually listed in the spec The OpenXR™ 1.1.40 Specification (with all registered extensions)

    XR_ERROR_API_VERSION_UNSUPPORTED = -4,

What are you setting in XrApplicationInfo.apiVersion? Older code and examples often use XR_CURRENT_API_VERSION which was fine when there was only OpenXR 1.0. Now OpenXR 1.1 is out and you need to be careful because few runtimes support OpenXR 1.1 yet.

XR_CURRENT_API_VERSION is a macro that is defined in openxr.h, which means that if your project brings its own openxr.h header from an OpenXR 1.0 SDK, it will resolve to an OpenXR 1.0 version. If openxr.h comes from an OpenXR 1.1 SDK, it will resolve to OpenXR 1.1.

Since OpenXR 1.1 the openxr.h header comes with the XR_API_VERSION_1_0 which is better to use because it won’t silently upgrade your OpenXR minor version by simply upgrading the openxr.h header.

1 Like

Yeah. I figured out that much. The big question is why the tutorial works, but not the same code in my own project.

Both apps write:

 28/08 22:15:06.223 {INFO}    [CAPI] LibOVR module is located at C:\Program Files\Oculus\Support\oculus-runtime\LibOVRRTImpl64_1.dll
'OpenXRTutorialChapter3.exe' (Win32): Loaded 'C:\Windows\System32\uxtheme.dll'. 
28/08 22:15:06.226 {INFO}    [Client] Connected to the server running version (prod = 1).1.100.0(build = 0) feature version = 0. Client runs version (prod = 1).1.100.0(build = 0) feature version = 0
28/08 22:15:06.226 {INFO}    [CAPI] ovr_Initialize success

But xrCreateInstance fails on mine with this rather wierd error

Error [GENERAL | xrCreateInstance | OpenXR-Loader] : LoaderInstance::CreateInstance chained CreateInstance call failed Error [GENERAL | xrCreateInstance | OpenXR-Loader] : xrCreateInstance failed 28/08 22:15:42.103 {DEBUG} [OXR] xrNegotiateLoaderRuntimeInterface loading 1.1.38 Error [GENERAL | xrCreateInstance | OpenXR-Loader] : LoaderInstance::CreateInstance chained CreateInstance call failed Error [GENERAL | xrCreateInstance | OpenXR-Loader] : xrCreateInstance failed

I checked the registry, and the 64-bit runtime is set correctly and both apps are Win64.

I’ll keep debugging but thanks :wink:

Haha. I actually read about setting to older API version, but I accidentially set it in the chapter 3 example (which had an older SDK). When I set it in the correct project, it worked. Stupid med LOL :slight_smile:

But thanks a lot! Now I can get on with it :smiley: