diff --git a/plugins/hifiSixense/src/SixenseManager.cpp b/plugins/hifiSixense/src/SixenseManager.cpp index b534c09055..455fdd2b5e 100644 --- a/plugins/hifiSixense/src/SixenseManager.cpp +++ b/plugins/hifiSixense/src/SixenseManager.cpp @@ -13,6 +13,9 @@ #ifdef HAVE_SIXENSE #include +#else +#define SIXENSE_FAILURE -1 +#define SIXENSE_SUCCESS 0 #endif #include @@ -43,6 +46,14 @@ static const unsigned int BUTTON_TRIGGER = 1U << 8; const glm::vec3 SixenseManager::DEFAULT_AVATAR_POSITION { -0.25f, -0.35f, -0.3f }; // in hydra frame const float SixenseManager::CONTROLLER_THRESHOLD { 0.35f }; +bool SixenseManager::_sixenseLoaded = false; + +#define BAIL_IF_NOT_LOADED \ + if (!_sixenseLoaded) { \ + return; \ + } + + const QString SixenseManager::NAME = "Sixense"; const QString SixenseManager::HYDRA_ID_STRING = "Razer Hydra"; @@ -89,11 +100,12 @@ void SixenseManager::activate() { userInputMapper->registerDevice(_inputDevice); loadSettings(); - sixenseInit(); + _sixenseLoaded = (sixenseInit() == SIXENSE_SUCCESS); #endif } void SixenseManager::deactivate() { + BAIL_IF_NOT_LOADED InputPlugin::deactivate(); #ifdef HAVE_SIXENSE @@ -114,12 +126,14 @@ void SixenseManager::deactivate() { } void SixenseManager::setSixenseFilter(bool filter) { + BAIL_IF_NOT_LOADED #ifdef HAVE_SIXENSE sixenseSetFilterEnabled(filter ? 1 : 0); #endif } void SixenseManager::pluginUpdate(float deltaTime, bool jointsCaptured) { + BAIL_IF_NOT_LOADED _inputDevice->update(deltaTime, jointsCaptured); if (_inputDevice->_requestReset) { _container->requestReset(); @@ -128,6 +142,7 @@ void SixenseManager::pluginUpdate(float deltaTime, bool jointsCaptured) { } void SixenseManager::InputDevice::update(float deltaTime, bool jointsCaptured) { + BAIL_IF_NOT_LOADED #ifdef HAVE_SIXENSE _buttonPressedMap.clear(); @@ -246,6 +261,7 @@ void SixenseManager::InputDevice::update(float deltaTime, bool jointsCaptured) { } void SixenseManager::InputDevice::setDebugDrawRaw(bool flag) { + BAIL_IF_NOT_LOADED _debugDrawRaw = flag; if (!flag) { DebugDraw::getInstance().removeMyAvatarMarker("SIXENSE_RAW_LEFT"); @@ -254,6 +270,7 @@ void SixenseManager::InputDevice::setDebugDrawRaw(bool flag) { } void SixenseManager::InputDevice::setDebugDrawCalibrated(bool flag) { + BAIL_IF_NOT_LOADED _debugDrawCalibrated = flag; if (!flag) { DebugDraw::getInstance().removeMyAvatarMarker("SIXENSE_CALIBRATED_LEFT"); @@ -281,6 +298,7 @@ static bool calibrationRequested(SixenseControllerData* controllers) { } void SixenseManager::InputDevice::updateCalibration(SixenseControllerData* controllers) { + BAIL_IF_NOT_LOADED const SixenseControllerData* dataLeft = controllers; const SixenseControllerData* dataRight = controllers + 1; @@ -365,11 +383,13 @@ void SixenseManager::InputDevice::updateCalibration(SixenseControllerData* contr #endif // HAVE_SIXENSE void SixenseManager::InputDevice::focusOutEvent() { + BAIL_IF_NOT_LOADED _axisStateMap.clear(); _buttonPressedMap.clear(); }; void SixenseManager::InputDevice::handleButtonEvent(unsigned int buttons, bool left) { + BAIL_IF_NOT_LOADED using namespace controller; if (buttons & BUTTON_0) { _buttonPressedMap.insert(left ? BACK : START); @@ -395,6 +415,7 @@ void SixenseManager::InputDevice::handleButtonEvent(unsigned int buttons, bool l } void SixenseManager::InputDevice::handlePoseEvent(float deltaTime, glm::vec3 position, glm::quat rotation, bool left) { + BAIL_IF_NOT_LOADED #ifdef HAVE_SIXENSE auto hand = left ? controller::StandardPoseChannel::LEFT_HAND : controller::StandardPoseChannel::RIGHT_HAND; diff --git a/plugins/hifiSixense/src/SixenseManager.h b/plugins/hifiSixense/src/SixenseManager.h index 0de5fe93aa..37da7358e0 100644 --- a/plugins/hifiSixense/src/SixenseManager.h +++ b/plugins/hifiSixense/src/SixenseManager.h @@ -98,6 +98,8 @@ private: static const QString NAME; static const QString HYDRA_ID_STRING; + + static bool _sixenseLoaded; }; #endif // hifi_SixenseManager_h diff --git a/plugins/hifiSixense/src/SixenseSupportOSX.cpp b/plugins/hifiSixense/src/SixenseSupportOSX.cpp index 85e0f3fe48..fce2ea023b 100644 --- a/plugins/hifiSixense/src/SixenseSupportOSX.cpp +++ b/plugins/hifiSixense/src/SixenseSupportOSX.cpp @@ -63,6 +63,9 @@ void unloadSixense() { // sixense.h wrapper for OSX dynamic linking int sixenseInit() { loadSixense(); + if (!SIXENSE || !SIXENSE->isLoaded()) { + return SIXENSE_FAILURE; + } return FORWARD(); } int sixenseExit() {