Echoleta
Echoleta

Reputation: 121

openxr xrEnumerateApiLayerProperties() throws internal exception from unknown type

I have written a simple function to check that the validation layers I want to load are indeed actually present. To do this, I'm invoking xrEnumerateApiLayerProperties() to get a list of all XrApiLayerProperties which I then can iterate over to verify that the layers I want to use are present.

bool OpenXRWrapper::checkValidationLayerSupport()
{
    uint32_t propertyCount = 0;
    XrResult result = xrEnumerateApiLayerProperties(0, &propertyCount, nullptr);
    std::vector<XrApiLayerProperties> availableAPILayers(propertyCount);
    result = xrEnumerateApiLayerProperties(propertyCount, nullptr, availableAPILayers.data());

    std::cout << "\n(OpenXR) Required Validation Layers: " << std::endl;
    bool allFound = true;
    for (const char* layer : layerNames) { /* Check that needed api layers are present */ }

    return allFound;
}

The issue arises during the second call to xrEnumerateApiLayerProperties() where I encounter the following error:

Error [GENERAL | xrEnumerateApiLayerProperties | OpenXR-Loader] : VUID-XrApiLayerProperties-type-type: unknown type in api_layer_properties
Error [GENERAL | xrEnumerateApiLayerProperties | OpenXR-Loader] : Failed ApiLayerInterface::GetApiLayerProperties

This is not originating from my code, so I dug into the OpenXR source and found where the error was being thrown: https://github.com/KhronosGroup/OpenXR-SDK-Source/blob/455583cc6ddb463f7433fc0e9bc2a4b9b0c943c6/src/loader/api_layer_interface.cpp#L53

The error seems to suggest that somehow OpenXR is not getting a valid XR type in the properties structure, but I'm failing to see why that may be happening. I'm not sure if this is a problem with my environment, or if I'm missing something in the documentation about how to correctly use xrEnumerateApiLayerProperties()

The first time I came across the error, I realized that I didn't have my OpenXR runtime going (SteamVR). After booting it up and trying the program again, I still ended up hitting the same error.

As a sanity check, I also verified that removing calls to my checkValidationLayerSupport() method did indeed allow the program to complete. Interestingly, the layer that I wanted to load did succeed in loading, as evident by my programs output:

Loaded 'C:\Users\[REDACTED]\OpenXRSDKSource\build\src\api_layers\XrApiLayer_core_validation.dll'. Symbols loaded.

One thing I would like to do but I actually don't know how to do is to attach a debugger to the OpenXR source such that I can see exactly what type it is that's making OpenXR error out- maybe that would give some clues as to what is going on.

Upvotes: 0

Views: 103

Answers (1)

Echoleta
Echoleta

Reputation: 121

Finding the error in the OpenXR source was a pretty big hint that eventually lead to the answer; OpenXR is expecting the structs in the array to be initialized with the correct type. I was confused since this diverged from the patterns that Khronos used in Vulkan. To get the above source to succeed in querying for API Layers, I simply had to iterate over the XrApiLayerProperties in the availableAPILayers vector and initialize the type to XR_TYPE_API_LAYER_PROPERTIES

std::vector<XrApiLayerProperties> availableAPILayers(propertyCount);
for (XrApiLayerProperties& properties : availableAPILayers) {
    properties.type = XR_TYPE_API_LAYER_PROPERTIES;
}

The above source also contained another error that emerged from my debugging search and that was the nullptr being passed to xrEnumerateApiLayerProperties() during that second call- it still requires a valid pointer.

    result = xrEnumerateApiLayerProperties(propertyCount, &propertyCount, availableAPILayers.data());

Upvotes: 0

Related Questions