mirror of
https://github.com/overte-org/overte.git
synced 2025-04-14 07:47:30 +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 {
|
||||
if (!OVR_SUCCESS(ovr_Initialize(nullptr))) {
|
||||
qDebug() << "OculusBaseDisplayPlugin : ovr_Initialize() failed";
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -48,6 +49,7 @@ bool OculusBaseDisplayPlugin::isSupported() const {
|
|||
if (!OVR_SUCCESS(result)) {
|
||||
ovrErrorInfo error;
|
||||
ovr_GetLastErrorInfo(&error);
|
||||
qDebug() << "OculusBaseDisplayPlugin : ovr_Create() failed" << result << error.Result << error.ErrorString;
|
||||
ovr_Shutdown();
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -72,10 +72,7 @@ mat4 toGlm(const vr::HmdMatrix34_t& m) {
|
|||
}
|
||||
|
||||
bool OpenVrDisplayPlugin::isSupported() const {
|
||||
auto hmd = acquireOpenVrSystem();
|
||||
bool success = nullptr != hmd;
|
||||
releaseOpenVrSystem();
|
||||
return success;
|
||||
return vr::VR_IsHmdPresent();
|
||||
}
|
||||
|
||||
void OpenVrDisplayPlugin::activate() {
|
||||
|
|
|
@ -23,11 +23,11 @@ using Lock = std::unique_lock<Mutex>;
|
|||
static int refCount { 0 };
|
||||
static Mutex mutex;
|
||||
static vr::IVRSystem* activeHmd { nullptr };
|
||||
static bool hmdPresent = vr::VR_IsHmdPresent();
|
||||
|
||||
static const uint32_t RELEASE_OPENVR_HMD_DELAY_MS = 5000;
|
||||
|
||||
vr::IVRSystem* acquireOpenVrSystem() {
|
||||
bool hmdPresent = vr::VR_IsHmdPresent();
|
||||
if (hmdPresent) {
|
||||
Lock lock(mutex);
|
||||
if (!activeHmd) {
|
||||
|
@ -53,24 +53,7 @@ void releaseOpenVrSystem() {
|
|||
--refCount;
|
||||
if (0 == refCount) {
|
||||
qCDebug(displayplugins) << "openvr: zero refcount, deallocate VR system";
|
||||
// Avoid spamming the VR system with activate/deactivate calls at system startup by
|
||||
// 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();
|
||||
//});
|
||||
vr::VR_Shutdown();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,10 +48,7 @@ static const QString RENDER_CONTROLLERS = "Render Hand Controllers";
|
|||
const QString ViveControllerManager::NAME = "OpenVR";
|
||||
|
||||
bool ViveControllerManager::isSupported() const {
|
||||
auto hmd = acquireOpenVrSystem();
|
||||
bool success = hmd != nullptr;
|
||||
releaseOpenVrSystem();
|
||||
return success;
|
||||
return vr::VR_IsHmdPresent();
|
||||
}
|
||||
|
||||
void ViveControllerManager::activate() {
|
||||
|
|
Loading…
Reference in a new issue