xrGetSystemId returns error code -2

OS: Windows 10
Device: Oculus Quest 2
Runtime: SteamVR
OpenXR version: 1.0.22
OpenXR-SDK-Source version built: 1.0.26 (because, I don’t need eye tracking, and Oculus Quest 2 dosn’t has it)

Hi.
I create my own application to interact with VR and can you help me with it, pls? When I try to get system id, I get error code -2. I know that error code from xrGetSystemProperties, but I don’t use that function nowhere in code listed below, and this error code appiarances only after xrGetSystemId.
Maybe, somebody knows how to fix it?
Thx, in advance!

Some logs:

Verbose [GENERAL | xrCreateInstance | OpenXR-Loader] : Entering loader trampoline
Info [GENERAL |  | OpenXR-Loader] : RuntimeManifestFile::FindManifestFiles - using registry-specified runtime file C:\My\Steam\steamapps\common\SteamVR\steamxr_win64.json
Info [GENERAL |  | OpenXR-Loader] : RuntimeManifestFile::CreateIfValid - attempting to load C:\My\Steam\steamapps\common\SteamVR\steamxr_win64.json
Info [GENERAL | xrCreateInstance | OpenXR-Loader] : RuntimeInterface::LoadRuntime succeeded loading runtime defined in manifest file C:\My\Steam\steamapps\common\SteamVR\steamxr_win64.json using interface version 1 and OpenXR API version 1.0
Info [GENERAL | xrCreateInstance | OpenXR-Loader] : ApiLayerInterface::LoadApiLayers succeeded loading layer XR_APILAYER_MBUCCHIA_toolkit using interface version 1 and OpenXR API version 1.0
Info [GENERAL | xrCreateInstance | OpenXR-Loader] : ApiLayerInterface::LoadApiLayers succeeded loading layer XR_APILAYER_LUNARG_core_validation using interface version 1 and OpenXR API version 1.0
Verbose [GENERAL | xrCreateInstance | OpenXR-Loader] : Entering LoaderInstance::CreateInstance
Core Validation output type: text, first time = true
Verbose [GENERAL | xrCreateInstance | OpenXR-Loader] : Entering loader terminator
Verbose [GENERAL | xrCreateInstance | OpenXR-Loader] : Completed loader terminator
Verbose [GENERAL | xrDestroyInstance | OpenXR-Loader] : Entering loader terminator
Verbose [GENERAL | xrDestroyInstance | OpenXR-Loader] : Completed loader terminator
Core Validation output type: text, first time = false
Verbose [GENERAL | xrCreateInstance | OpenXR-Loader] : Entering loader terminator
Verbose [GENERAL | xrCreateInstance | OpenXR-Loader] : Completed loader terminator
Info [GENERAL | xrCreateInstance | OpenXR-Loader] : LoaderInstance::CreateInstance succeeded with 2 layers enabled and runtime interface - created instance = 0x00000296268fa580
Verbose [GENERAL | xrCreateInstance | OpenXR-Loader] : Completed loader trampoline
[VALID_ERROR | VUID-XrSystemProperties-next-next | xrGetSystemProperties]: Invalid structure(s) in "next" chain for XrSystemProperties struct "next"
  Objects:
   [0] - XrInstance (0x00000296268fa580)
[VALID_ERROR | VUID-xrGetSystemProperties-properties-parameter | xrGetSystemProperties]: Command xrGetSystemProperties param properties is invalid
  Objects:
   [0] - XrInstance (0x00000296268fa580)
Error: Failed to get system: -2

Application code:

#include <vulkan/vulkan.h>
#define XR_USE_GRAPHICS_API_VULKAN
#include <openxr/openxr.h>
#include <openxr/openxr_platform.h>

#include <iostream>
#include <cstring>

using namespace std;

XrInstance createInstance()
{
    XrInstance instance;

    static const char* const applicationName = "OpenXR Example";
    static const unsigned int majorVersion = 0;
    static const unsigned int minorVersion = 1;
    static const unsigned int patchVersion = 0;
    static const char* const layerNames[] = { "XR_APILAYER_LUNARG_core_validation" };
    static const char* const extensionNames[] = {
        "XR_KHR_vulkan_enable",
        "XR_KHR_vulkan_enable2",
        "XR_EXT_debug_utils"
    };

    XrInstanceCreateInfo instanceCreateInfo{};
    instanceCreateInfo.type = XR_TYPE_INSTANCE_CREATE_INFO;
    instanceCreateInfo.createFlags = 0;
    strcpy(instanceCreateInfo.applicationInfo.applicationName, applicationName);
    instanceCreateInfo.applicationInfo.applicationVersion = XR_MAKE_VERSION(majorVersion, minorVersion, patchVersion);
    strcpy(instanceCreateInfo.applicationInfo.engineName, applicationName);
    instanceCreateInfo.applicationInfo.engineVersion = XR_MAKE_VERSION(majorVersion, minorVersion, patchVersion);
    instanceCreateInfo.applicationInfo.apiVersion = XR_CURRENT_API_VERSION;
    instanceCreateInfo.enabledApiLayerCount = 1;
    instanceCreateInfo.enabledApiLayerNames = layerNames;
    instanceCreateInfo.enabledExtensionCount = sizeof(extensionNames) / sizeof(const char*);
    instanceCreateInfo.enabledExtensionNames = extensionNames;

    XrResult result = xrCreateInstance(&instanceCreateInfo, &instance);

    if (result != XR_SUCCESS)
    {
        cerr << "Failed to create OpenXR instance: " << result << endl;
        return XR_NULL_HANDLE;
    }

    return instance;
}

void destroyInstance(XrInstance instance)
{
    xrDestroyInstance(instance);
}

XrSystemId getSystem(XrInstance instance)
{
    XrSystemId systemID;

    XrSystemGetInfo systemGetInfo{};
    systemGetInfo.type = XR_TYPE_SYSTEM_GET_INFO;
    systemGetInfo.formFactor = XR_FORM_FACTOR_HEAD_MOUNTED_DISPLAY;

    XrResult result = xrGetSystem(instance, &systemGetInfo, &systemID);

    if (result != XR_SUCCESS)
    {
        cerr << "Failed to get system: " << result << endl;
        return XR_NULL_SYSTEM_ID;
    }

    return systemID;
}

int main(int, char**)
{
    XrInstance instance = createInstance();
    XrSystemId system = getSystem(instance);

    destroyInstance(instance);

    return 0;
}

The validation error

[VALID_ERROR | VUID-XrSystemProperties-next-next | xrGetSystemProperties]: Invalid structure(s) in "next" chain for XrSystemProperties struct "next"

suggests that the next pointer is pointing to an invalid structure (although I’m not sure why the validation layer is referring to xrGetSystemProperties?).
Have you tried explicitly setting systemGetInfo.next = nullptr; before calling xrGetSystem?

Yes, I have tried to set .next to nullptr exlicitly/

Are you absolutely sure you get this error when running this version of the app that has no call to xrGetSystemProperties?

I do know that unfortunately the validation layer is a little under-loved, it’s possible there’s a bug in the validation layer. What version of the SDK are you using and how are you building against it?

(It builds and appears to run successfully for me on Debian Bullseye against a recent Monado build, using the sdk in libopenxr-dev: built with c++ -o forum-openxr forum-openxr.cpp -lopenxr_loader -lvulkan )

Yes, I get this error in that program. I build the app with CMake and I use vcpkg:

cmake_minimum_required(VERSION 3.22)

set(CMAKE_TOOLCHAIN_FILE $ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake CACHE STRING "Vcpkg toolchain file")
set(VCPKG_TARGET_TRIPLET x64-windows-static CACHE STRING "Vcpkg triplet")
set(VCPKG_BUILD_TYPE x64 CACHE STRING "Vcpkg build type")

project(openxr-test)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED True)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/deploy)

find_package(OpenXR CONFIG REQUIRED)
find_package(Vulkan REQUIRED)

add_executable(openxr-test main.cpp)

target_link_libraries(openxr-test PRIVATE OpenXR::headers OpenXR::openxr_loader 
                                          Vulkan::Vulkan)

And I wrote about SDK from OpenXR-SDK-Source with version 1.0.26

Since you have OpenXR Toolkit installed, its API layer might be chaining the call to xrGetSystem() and inserting its own call to xrGetSystemProperties() after it, before returning from the original call.

You might want to update OpenXR Toolkit to the latest version in case there is a bug in it, or test with it disabled. @mbucchia might know more.

Definitely try without OpenXR Toolkit… I would not expect at all that it will play nice with the validation layer…

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