Fixed memory corruption in case of gamepads with large buttons count.

SEvent::SJoystickEvent::NUMBER_OF_BUTTONS is a constant value and is equal to 32. In practice we don't expect any gamepad that has over 32 buttons. However some wireless mices are incorrectly detected as gamepads and they report for example 69 available buttons. Just resize m_buttonPressed array to be equal to the reported buttons count.
This commit is contained in:
Deve 2016-04-10 00:54:24 +02:00
parent 8c29fb01f6
commit 29e4d4a0bc
2 changed files with 4 additions and 2 deletions

View File

@ -57,7 +57,8 @@ GamePadDevice::GamePadDevice(const int irr_index, const std::string &name,
m_axis_ok[i] = false;
}
for(int n=0; n<SEvent::SJoystickEvent::NUMBER_OF_BUTTONS; n++)
m_buttonPressed = new bool[button_count];
for(int n=0; n<button_count; n++)
m_buttonPressed[n] = false;
} // GamePadDevice
@ -66,6 +67,7 @@ GamePadDevice::GamePadDevice(const int irr_index, const std::string &name,
*/
GamePadDevice::~GamePadDevice()
{
delete[] m_buttonPressed;
delete[] m_prev_axis_directions;
delete[] m_prev_axis_value;
delete[] m_axis_ok;

View File

@ -31,7 +31,7 @@ class GamepadConfig;
class GamePadDevice : public InputDevice
{
void resetAxisDirection(const int axis, Input::AxisDirection direction);
bool m_buttonPressed[SEvent::SJoystickEvent::NUMBER_OF_BUTTONS];
bool* m_buttonPressed;
Input::AxisDirection *m_prev_axis_directions;