diff --git a/src/input/evdev.c b/src/input/evdev.c index 04e8ce2..350a124 100644 --- a/src/input/evdev.c +++ b/src/input/evdev.c @@ -105,6 +105,9 @@ static const int hat_constants[3][3] = {{HAT_UP | HAT_LEFT, HAT_UP, HAT_UP | HAT // Determines the maximum motion amount before allowing movement #define MOUSE_EMULATION_DEADZONE 2 +// Limited by number of bits in activeGamepadMask +#define MAX_GAMEPADS 16 + static struct input_device* devices = NULL; static int numDevices = 0; static int assignedControllerIds = 0; @@ -283,7 +286,7 @@ static bool evdev_handle_event(struct input_event *ev, struct input_device *dev) } if (dev->gamepadModified) { if (dev->controllerId < 0) { - for (int i = 0; i < 4; i++) { + for (int i = 0; i < MAX_GAMEPADS; i++) { if ((assignedControllerIds & (1 << i)) == 0) { assignedControllerIds |= (1 << i); dev->controllerId = i; diff --git a/src/input/sdl.c b/src/input/sdl.c index 3f48b98..939e704 100644 --- a/src/input/sdl.c +++ b/src/input/sdl.c @@ -43,7 +43,10 @@ typedef struct _GAMEPAD_STATE { bool initialized; } GAMEPAD_STATE, *PGAMEPAD_STATE; -static GAMEPAD_STATE gamepads[4]; +// Limited by number of bits in activeGamepadMask +#define MAX_GAMEPADS 16 + +static GAMEPAD_STATE gamepads[MAX_GAMEPADS]; static int keyboard_modifiers; static int activeGamepadMask = 0; @@ -52,7 +55,7 @@ int sdl_gamepads = 0; static PGAMEPAD_STATE get_gamepad(SDL_JoystickID sdl_id, bool add) { // See if a gamepad already exists - for (int i = 0;i<4;i++) { + for (int i = 0;i= 0) { @@ -353,7 +356,7 @@ int sdlinput_handle_event(SDL_Window* window, SDL_Event* event) { } void sdlinput_rumble(unsigned short controller_id, unsigned short low_freq_motor, unsigned short high_freq_motor) { - if (controller_id >= 4) + if (controller_id >= MAX_GAMEPADS) return; PGAMEPAD_STATE state = &gamepads[controller_id];