From 06056b80d73df0b4c1fa4a061f9a8b962692f144 Mon Sep 17 00:00:00 2001 From: praydog Date: Fri, 25 Aug 2023 15:37:09 -0700 Subject: [PATCH] OpenXR: Fix "Attempt to reinitialize" not working correctly --- src/mods/vr/runtimes/OpenXR.cpp | 4 ++-- src/mods/vr/runtimes/OpenXR.hpp | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/mods/vr/runtimes/OpenXR.cpp b/src/mods/vr/runtimes/OpenXR.cpp index 24ec55aa..58be1fa6 100644 --- a/src/mods/vr/runtimes/OpenXR.cpp +++ b/src/mods/vr/runtimes/OpenXR.cpp @@ -561,10 +561,10 @@ void OpenXR::destroy() { xrDestroySession(this->session); } - if (this->instance != nullptr) { + /*if (this->instance != nullptr) { xrDestroyInstance(this->instance); this->instance = nullptr; - } + }*/ this->session = nullptr; this->session_ready = false; diff --git a/src/mods/vr/runtimes/OpenXR.hpp b/src/mods/vr/runtimes/OpenXR.hpp index 5b58c414..2fa3a217 100644 --- a/src/mods/vr/runtimes/OpenXR.hpp +++ b/src/mods/vr/runtimes/OpenXR.hpp @@ -181,7 +181,10 @@ struct OpenXR final : public VRRuntime { std::recursive_mutex event_mtx{}; std::recursive_mutex swapchain_mtx{}; - XrInstance instance{XR_NULL_HANDLE}; + // Making it static because for some reason destroying it doesn't actually completely destroy everything. + // So we must make sure it always exists if we ever re-initialize OpenXR. + static inline XrInstance instance{XR_NULL_HANDLE}; + XrSession session{XR_NULL_HANDLE}; XrSpace stage_space{XR_NULL_HANDLE}; XrSpace view_space{XR_NULL_HANDLE}; // for generating view matrices