mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 14:18:24 +02:00
OpenVr: fix for conflict between openvr and oculus display plugins
* Call vr::VR_Shutdown() when ref-count goes to zero. The ref-count is ncessary because the vr::IVRSystem poitner is shared between the the openvr input and display plugins. * OpenVR plugins options will display in the menu if vr::VR_IsHmdPresent() is true. This is faster then initializing all of openvr and less likely to conflict with the oculus display plugin.
This commit is contained in:
parent
90f0821c2b
commit
c8e6aee3e7
4 changed files with 6 additions and 27 deletions
|
@ -39,6 +39,7 @@ glm::mat4 OculusBaseDisplayPlugin::getHeadPose(uint32_t frameIndex) const {
|
||||||
|
|
||||||
bool OculusBaseDisplayPlugin::isSupported() const {
|
bool OculusBaseDisplayPlugin::isSupported() const {
|
||||||
if (!OVR_SUCCESS(ovr_Initialize(nullptr))) {
|
if (!OVR_SUCCESS(ovr_Initialize(nullptr))) {
|
||||||
|
qDebug() << "OculusBaseDisplayPlugin : ovr_Initialize() failed";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,6 +49,7 @@ bool OculusBaseDisplayPlugin::isSupported() const {
|
||||||
if (!OVR_SUCCESS(result)) {
|
if (!OVR_SUCCESS(result)) {
|
||||||
ovrErrorInfo error;
|
ovrErrorInfo error;
|
||||||
ovr_GetLastErrorInfo(&error);
|
ovr_GetLastErrorInfo(&error);
|
||||||
|
qDebug() << "OculusBaseDisplayPlugin : ovr_Create() failed" << result << error.Result << error.ErrorString;
|
||||||
ovr_Shutdown();
|
ovr_Shutdown();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,10 +72,7 @@ mat4 toGlm(const vr::HmdMatrix34_t& m) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OpenVrDisplayPlugin::isSupported() const {
|
bool OpenVrDisplayPlugin::isSupported() const {
|
||||||
auto hmd = acquireOpenVrSystem();
|
return vr::VR_IsHmdPresent();
|
||||||
bool success = nullptr != hmd;
|
|
||||||
releaseOpenVrSystem();
|
|
||||||
return success;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenVrDisplayPlugin::activate() {
|
void OpenVrDisplayPlugin::activate() {
|
||||||
|
|
|
@ -23,11 +23,11 @@ using Lock = std::unique_lock<Mutex>;
|
||||||
static int refCount { 0 };
|
static int refCount { 0 };
|
||||||
static Mutex mutex;
|
static Mutex mutex;
|
||||||
static vr::IVRSystem* activeHmd { nullptr };
|
static vr::IVRSystem* activeHmd { nullptr };
|
||||||
static bool hmdPresent = vr::VR_IsHmdPresent();
|
|
||||||
|
|
||||||
static const uint32_t RELEASE_OPENVR_HMD_DELAY_MS = 5000;
|
static const uint32_t RELEASE_OPENVR_HMD_DELAY_MS = 5000;
|
||||||
|
|
||||||
vr::IVRSystem* acquireOpenVrSystem() {
|
vr::IVRSystem* acquireOpenVrSystem() {
|
||||||
|
bool hmdPresent = vr::VR_IsHmdPresent();
|
||||||
if (hmdPresent) {
|
if (hmdPresent) {
|
||||||
Lock lock(mutex);
|
Lock lock(mutex);
|
||||||
if (!activeHmd) {
|
if (!activeHmd) {
|
||||||
|
@ -53,24 +53,7 @@ void releaseOpenVrSystem() {
|
||||||
--refCount;
|
--refCount;
|
||||||
if (0 == refCount) {
|
if (0 == refCount) {
|
||||||
qCDebug(displayplugins) << "openvr: zero refcount, deallocate VR system";
|
qCDebug(displayplugins) << "openvr: zero refcount, deallocate VR system";
|
||||||
// Avoid spamming the VR system with activate/deactivate calls at system startup by
|
vr::VR_Shutdown();
|
||||||
// putting in a delay before we destory the shutdown the VR subsystem
|
|
||||||
|
|
||||||
// FIXME releasing the VR system at all seems to trigger an exception deep inside the Oculus DLL.
|
|
||||||
// disabling for now.
|
|
||||||
//QTimer* releaseTimer = new QTimer();
|
|
||||||
//releaseTimer->singleShot(RELEASE_OPENVR_HMD_DELAY_MS, [releaseTimer] {
|
|
||||||
// Lock lock(mutex);
|
|
||||||
// qDebug() << "Delayed openvr destroy activated";
|
|
||||||
// if (0 == refCount && nullptr != activeHmd) {
|
|
||||||
// qDebug() << "Delayed openvr destroy: releasing resources";
|
|
||||||
// activeHmd = nullptr;
|
|
||||||
// vr::VR_Shutdown();
|
|
||||||
// } else {
|
|
||||||
// qDebug() << "Delayed openvr destroy: HMD still in use";
|
|
||||||
// }
|
|
||||||
// releaseTimer->deleteLater();
|
|
||||||
//});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,10 +48,7 @@ static const QString RENDER_CONTROLLERS = "Render Hand Controllers";
|
||||||
const QString ViveControllerManager::NAME = "OpenVR";
|
const QString ViveControllerManager::NAME = "OpenVR";
|
||||||
|
|
||||||
bool ViveControllerManager::isSupported() const {
|
bool ViveControllerManager::isSupported() const {
|
||||||
auto hmd = acquireOpenVrSystem();
|
return vr::VR_IsHmdPresent();
|
||||||
bool success = hmd != nullptr;
|
|
||||||
releaseOpenVrSystem();
|
|
||||||
return success;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViveControllerManager::activate() {
|
void ViveControllerManager::activate() {
|
||||||
|
|
Loading…
Reference in a new issue