Problems With GetVisibilityMask

After checking for the extension, I believe I am correctly obtaining the function address via

xrGetInstanceProcAddr(xr_instance, "xrGetVisibilityMaskKHR", (PFN_xrVoidFunction*)(&ext_xrGetVisibilityMaskKHR));

and calling the function via

XrVisibilityMaskKHR VisMask;
if (ext_xrGetVisibilityMaskKHR(xr_session, app_config_view, iView, XR_VISIBILITY_MASK_TYPE_HIDDEN_TRIANGLE_MESH_KHR, &VisMask) == XR_SUCCESS)
{
	int debug = 0;
}

However I get the error

ERROR (OpenXR) : Invalid XrStructureType -858993460 at address 0x5e3b2a8. Expected 'XR_TYPE_VISIBILITY_MASK_KHR'.

Which does not make sense, as I have provided a structure, and it is complaining that it is expecting a structure, but XR_TYPE_VISIBILITY_MASK_KHR is actually an enumeration, that identifies the structure I am passing down.

There no samples or code anywhere on the net demonstrating this capability so I am at a loss as to how to proceed. Clearly giving it the address of an enumeration will not work. The visibility mask is essential for performance.

Yes, but you have not initialized any of the structure members, in particular you have not initialized the .type and .next members:

XrVisibilityMaskKHR VisMask;
VisMask.type = XR_TYPE_VISIBILITY_MASK_KHR;
VisMaks.next = nullptr;
// initialize the remaining members of VisMask

This is very much idiomatic for OpenXR and used everywhere in the API, please take a look at what any other piece of code that passes any type of struct to OpenXR does.

1 Like

Yep, that’s the issue. You have to initialize the structures before you pass them in. For reference, here’s the relevant part of the spec: for the type field, https://www.khronos.org/registry/OpenXR/specs/1.0/html/xrspec.html#valid-usage-for-structure-types for the next pointer, https://www.khronos.org/registry/OpenXR/specs/1.0/html/xrspec.html#valid-usage-for-structure-pointer-chains

Thanks for the help all I appreciate it.