fix crash on mac when sixense DLL can't be loaded

This commit is contained in:
Brad Hefta-Gaub 2015-12-22 00:54:48 -08:00
parent 3dfc48e205
commit eff830ad4b
3 changed files with 27 additions and 1 deletions

View file

@ -13,6 +13,9 @@
#ifdef HAVE_SIXENSE
#include <sixense.h>
#else
#define SIXENSE_FAILURE -1
#define SIXENSE_SUCCESS 0
#endif
#include <QCoreApplication>
@ -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;

View file

@ -98,6 +98,8 @@ private:
static const QString NAME;
static const QString HYDRA_ID_STRING;
static bool _sixenseLoaded;
};
#endif // hifi_SixenseManager_h

View file

@ -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() {