From 3cf7a8008ee8bd90ee00b9e6d9949cf54aa0ef1f Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 29 Jan 2015 17:17:29 +1100 Subject: [PATCH] Fix crash on joystick access (if SDL's not found) D985 by @pgi --- source/gameengine/GameLogic/SCA_JoystickSensor.cpp | 12 ++++++------ 1 file 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(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(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(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)