Pointer functions are invalid when in Release?


This code in OpenXR SDK Source in Sample Project hello_xr causes problems when in Release.

PFN_xrGetD3D12GraphicsRequirementsKHR pfnGetD3D12GraphicsRequirementsKHR = nullptr;
CHECK_XRCMD(xrGetInstanceProcAddr(instance, "xrGetD3D12GraphicsRequirementsKHR",

I’m curious as to what the solution is to make it work in Release since the same line causes a premature error in our code when starting VR.

The error in the sample project is

[13:15:41.311][Error  ] GraphicsPlugin parameter is required

My initial hunch was to build the openxr_loader.lib with the following defines, hoping that it would expose the xrGetD3D12GraphicsRequirementsKHR function, but that doesn’t seem to be the case.


Thank you in advance,

Alexander Kostov, Chaos

You definitely do not want XR_EXTENSION_PROTOTYPES - there is almost no case in which you want to define that.

If xrGetInstanceProcAddr returns nullptr for a given function, this typically means you don’t have that extension enabled. You need to enable the XR_KHR_D3D12_enable extension (in this case) to have access to that function.

I’m not sure how Release mode would affect things here - is it that release is breaking things in your app? Hello XR should work fine in Release builds.

I have XR_USE_GRAPHICS_API_D3D12, which enables the D3D12 extension,

//from openxr_platform.h

#define XR_KHR_D3D12_enable 1
#define XR_KHR_D3D12_enable_SPEC_VERSION  9

I have the same problem in Release with both my app and hello_xr.

You need to request the extension during the call to xrCreateInstance() as well:


See this example:

I already do this, but this was a really good pointer (pun intended) to where the root of the problem actually was.

Long story short, the cause is Dead-code optimization. The VS Compiler thinks it is smart enough to just remove the SelectExtensions() function altogether when in Release.

enabledExtensions results in an empty vector, thus causing the validation error later on.

PS: This is happening on the hello_xr project as well.

Thanks for the help! :wink:

Edit: If anyone stumbles upon this problem, the quick fix is to hardcode the enabledExtensions vector

const std::vector<const char*> enabledExtensions = { XR_KHR_D3D12_ENABLE_EXTENSION_NAME };

The smart way would be to tell the compiler not to touch functionality, which is actually used. :smiley:

hmm, so now I’m really confused, what change needs to be made to hello_xr? The extensions vector of const char * is definitely being used (in CreateInstanceInternal)… It is populated by the two std::transform calls with std::back_inserter making an output iterator.

Can you file an issue on https://github.com/KhronosGroup/OpenXR-SDK-Source so we can follow up on this and get it fixed?

Will do these days. The code in hello_xr is a wee bit different, but the result is the same in my case

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.