From 61ea8f83377952a8ca8e1cb5cf8ec1099ca8369f Mon Sep 17 00:00:00 2001 From: bruvzg <7645683+bruvzg@users.noreply.github.com> Date: Mon, 10 Jan 2022 13:43:44 +0200 Subject: [PATCH] Add joystick button index boundary check. Increase max. button number to 128 (max. buttons supported by DirectInput). --- core/input/input.cpp | 3 ++- core/input/input_enums.h | 2 +- doc/classes/@GlobalScope.xml | 7 +++++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/core/input/input.cpp b/core/input/input.cpp index c5540f926df..507a686cab1 100644 --- a/core/input/input.cpp +++ b/core/input/input.cpp @@ -892,7 +892,8 @@ void Input::set_event_dispatch_function(EventDispatchFunc p_function) { void Input::joy_button(int p_device, JoyButton p_button, bool p_pressed) { _THREAD_SAFE_METHOD_; Joypad &joy = joy_names[p_device]; - //printf("got button %i, mapping is %i\n", p_button, joy.mapping); + ERR_FAIL_INDEX((int)p_button, (int)JoyButton::MAX); + if (joy.last_buttons[(size_t)p_button] == p_pressed) { return; } diff --git a/core/input/input_enums.h b/core/input/input_enums.h index aa55316ec87..0282de21760 100644 --- a/core/input/input_enums.h +++ b/core/input/input_enums.h @@ -83,7 +83,7 @@ enum class JoyButton { PADDLE4 = 19, TOUCHPAD = 20, SDL_MAX = 21, - MAX = 36, // Android supports up to 36 buttons. + MAX = 128, // Android supports up to 36 buttons. DirectInput supports up to 128 buttons. }; enum class MIDIMessage { diff --git a/doc/classes/@GlobalScope.xml b/doc/classes/@GlobalScope.xml index 20a371c3d0e..be7ac1164e8 100644 --- a/doc/classes/@GlobalScope.xml +++ b/doc/classes/@GlobalScope.xml @@ -2134,8 +2134,11 @@ The number of SDL game controller buttons. - - The maximum number of game controller buttons: Android supports up to 36 buttons. + + The maximum number of game controller buttons supported by the engine. The actual limit may be lower on specific platforms: + - Android: Up to 36 buttons. + - Linux: Up to 80 buttons. + - Windows and macOS: Up to 128 buttons. An invalid game controller axis.