From 0fd630100fda7f702c84e6a475b006b3c7cf33cb Mon Sep 17 00:00:00 2001 From: divVerent Date: Sat, 26 Mar 2022 07:25:41 -0400 Subject: [PATCH] inpututil: allow an arbitrary number of gamepad buttons. (#2031) Fixes crash in inpututil when a gamepad with more than "allowed" buttons is connected. Closes #2027 --- inpututil/inpututil.go | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/inpututil/inpututil.go b/inpututil/inpututil.go index 752a1ef12..0c3081fbc 100644 --- a/inpututil/inpututil.go +++ b/inpututil/inpututil.go @@ -137,12 +137,9 @@ func (i *inputState) update() { for _, id := range i.gamepadIDsBuf { i.gamepadIDs[id] = struct{}{} - if _, ok := i.gamepadButtonDurations[id]; !ok { - i.gamepadButtonDurations[id] = make([]int, ebiten.GamepadButtonMax+1) - } n := ebiten.GamepadButtonNum(id) - if n > int(ebiten.GamepadButtonMax)+1 { - n = int(ebiten.GamepadButtonMax) + 1 + if n != len(i.gamepadButtonDurations[id]) { + i.gamepadButtonDurations[id] = make([]int, n) } for b := ebiten.GamepadButton(0); b < ebiten.GamepadButton(n); b++ { if ebiten.IsGamepadButtonPressed(id, b) {