UEVR icon indicating copy to clipboard operation
UEVR copied to clipboard

OpenXR not loaded: Could not create openxr system: XR_ERROR_FORM_FACTOR_UNAVAILABLE

Open Fribur opened this issue 2 years ago • 11 comments

First of all: AMAZING PRODUCT! Thanks so much for spending hundreds of hours of your time to bring to the VR world this gift!!!!

To the issue I observe (and I see on Discord also a few others). Config: Quest 3, Virtual Desktop Stream 1.29.10, SteamVR beta 2.2.4, Oculus App 60.0.0.162.352.

Error: Im checking & changing which OpenXR runtime is active via Oculus App and/or Steam VR (see an example of of of the 3 runtimes I tested in the attached pictures). Virtual Desktop Stream overrides both and configures itself as runtime when installing it. Trying to play "The Invincible".

  1. SteamVR-OpenXR: above error
  2. VirtualDesktop-OpenXR: above error
  3. Oculus OpenXR: works

For (1) and (2), it tried to connect to PC via Oculus Link, and Virtual Desktop: no difference. When using Virtual Desktop I tried to set OpenXR runtime in Virtual Desktop as "Automatic", "SteamVR", VDXR: no difference. Out of ideas what to do except for (3). Issue https://github.com/praydog/UEVR/issues/39 is definitely not resolved.

image image

Fribur avatar Jan 06 '24 00:01 Fribur

Doing some further research, I am suspecting this code section in CR.cpp might be to blame? https://github.com/praydog/UEVR/blob/46af040110430987a45849fb4693bdf8a678fa46/src/mods/VR.cpp#L367

in particular this piece of code to:

result = xrGetSystem(m_openxr->instance, &system_info, &m_openxr->system);

if (result != XR_SUCCESS) {
    m_openxr->error = "Could not create openxr system: " + m_openxr->get_result_string(result);
    spdlog::error("[VR] {}", m_openxr->error.value());

    return std::nullopt;
}

As I see it, UEVR is basically trying once to get the OpenXR System (xrGetSystem). According to the OpenXR reference guide, the system might be temporarily unavailable, and the application can re-try: "A return of XR_ERROR_FORM_FACTOR_UNAVAILABLE indicates the form factor is supported but temporarily unavailable; the application may retry xrGetSystem."

image

So what do you think about the suggestion to not immediately fail in line 373 if (result != XR_SUCCESS), but rather try a couple of times? Maybe 5 times with 50ms delay?

Fribur avatar Jan 06 '24 12:01 Fribur

I tried now the following without success :-( ..any idea why this step could fail? Note it works when I set Oculus as OpenXR runtime & use Oculus link/Airlink, but not with Virtual Desktop.

    // We may just be restarting OpenXR, so try to find an existing system first
    if (m_openxr->system == XR_NULL_SYSTEM_ID) {
        XrSystemGetInfo system_info{XR_TYPE_SYSTEM_GET_INFO};
        system_info.formFactor = m_openxr->form_factor;
        int counter = 0;
        do
        {
            result = xrGetSystem(m_openxr->instance, &system_info, &m_openxr->system);
            _sleep(50); //wait 50ms
            counter++;            
        } while (result != XR_SUCCESS && counter < 200);

        if (result != XR_SUCCESS) {
            char cstr[512];
            snprintf(cstr, sizeof(cstr), "Tried %d times, but could not create openxr system %s", counter, m_openxr->get_result_string(result).c_str());
            m_openxr->error = cstr;
            spdlog::error("[VR] {}", m_openxr->error.value());

            return std::nullopt;
        }
    } else {
        spdlog::info("[VR] Found existing openxr system");
    }

image

Fribur avatar Jan 06 '24 14:01 Fribur

@mbucchia found the solution. His words:

...one possible issue, that is rare, is that you have a bad environment variable, XR_RUNTIME_JSON that you set before to override the OpenXR runtime. This would take precedence over the registry and would also fool all the tools into displaying the wrong runtime as being selected

And of course he was correct: image As soon as I deleted this variable, re-booted, everything works correct! @praydog : I leave it up to you if/how you want to close and resolve this issue. I understand from discord chat you might want to add a check in UEVR that warns users of that.

Fribur avatar Jan 06 '24 20:01 Fribur

Or you can use the OpenXR tool to force Open XR at system level. I had the same error and this solved it.

Crrispy avatar Jan 07 '24 11:01 Crrispy