diff options
author | Campbell Barton <ideasman42@gmail.com> | 2015-01-29 09:17:29 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2015-01-29 09:17:29 +0300 |
commit | 3cf7a8008ee8bd90ee00b9e6d9949cf54aa0ef1f (patch) | |
tree | b3e237510a4f260124329900117b6274f0bea2a0 /source/gameengine/GameLogic/SCA_JoystickSensor.cpp | |
parent | 072d80a9de3adef632b8637649b169c4a895c1b9 (diff) |
Fix crash on joystick access (if SDL's not found)
D985 by @pgi
Diffstat (limited to 'source/gameengine/GameLogic/SCA_JoystickSensor.cpp')
-rw-r--r-- | source/gameengine/GameLogic/SCA_JoystickSensor.cpp | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/source/gameengine/GameLogic/SCA_JoystickSensor.cpp b/source/gameengine/GameLogic/SCA_JoystickSensor.cpp index 3cae3bcf160..e20dd8bcd74 100644 --- a/source/gameengine/GameLogic/SCA_JoystickSensor.cpp +++ b/source/gameengine/GameLogic/SCA_JoystickSensor.cpp @@ -351,8 +351,8 @@ PyObject *SCA_JoystickSensor::pyattr_get_axis_values(void *self_v, const KX_PYAT SCA_JoystickSensor* self = static_cast<SCA_JoystickSensor*>(self_v); SCA_Joystick *joy = ((SCA_JoystickManager *)self->m_eventmgr)->GetJoystickDevice(self->m_joyindex); - int axis_index= joy->GetNumberOfAxes(); - PyObject *list= PyList_New(axis_index); + int axis_index = (joy ? joy->GetNumberOfAxes() : 0); + PyObject *list = PyList_New(axis_index); while (axis_index--) { PyList_SET_ITEM(list, axis_index, PyLong_FromLong(joy->GetAxisPosition(axis_index))); @@ -371,7 +371,7 @@ PyObject *SCA_JoystickSensor::pyattr_get_axis_single(void *self_v, const KX_PYAT return NULL; } - return PyLong_FromLong(joy->GetAxisPosition(self->m_axis-1)); + return PyLong_FromLong(joy ? joy->GetAxisPosition(self->m_axis - 1) : 0); } PyObject *SCA_JoystickSensor::pyattr_get_hat_values(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) @@ -379,8 +379,8 @@ PyObject *SCA_JoystickSensor::pyattr_get_hat_values(void *self_v, const KX_PYATT SCA_JoystickSensor* self = static_cast<SCA_JoystickSensor*>(self_v); SCA_Joystick *joy = ((SCA_JoystickManager *)self->m_eventmgr)->GetJoystickDevice(self->m_joyindex); - int hat_index= joy->GetNumberOfHats(); - PyObject *list= PyList_New(hat_index); + int hat_index = (joy ? joy->GetNumberOfHats() : 0); + PyObject *list = PyList_New(hat_index); while (hat_index--) { PyList_SET_ITEM(list, hat_index, PyLong_FromLong(joy->GetHat(hat_index))); @@ -394,7 +394,7 @@ PyObject *SCA_JoystickSensor::pyattr_get_hat_single(void *self_v, const KX_PYATT SCA_JoystickSensor* self = static_cast<SCA_JoystickSensor*>(self_v); SCA_Joystick *joy = ((SCA_JoystickManager *)self->m_eventmgr)->GetJoystickDevice(self->m_joyindex); - return PyLong_FromLong(joy->GetHat(self->m_hat-1)); + return PyLong_FromLong(joy ? joy->GetHat(self->m_hat - 1) : 0); } PyObject *SCA_JoystickSensor::pyattr_get_num_axis(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) |