diff --git a/inpututil/inpututil.go b/inpututil/inpututil.go index 0c3081fbc..d3e50a730 100644 --- a/inpututil/inpututil.go +++ b/inpututil/inpututil.go @@ -137,10 +137,10 @@ func (i *inputState) update() { for _, id := range i.gamepadIDsBuf { i.gamepadIDs[id] = struct{}{} - n := ebiten.GamepadButtonNum(id) - if n != len(i.gamepadButtonDurations[id]) { - i.gamepadButtonDurations[id] = make([]int, n) + if _, ok := i.gamepadButtonDurations[id]; !ok { + i.gamepadButtonDurations[id] = make([]int, ebiten.GamepadButtonMax+1) } + n := ebiten.GamepadButtonNum(id) for b := ebiten.GamepadButton(0); b < ebiten.GamepadButton(n); b++ { if ebiten.IsGamepadButtonPressed(id, b) { i.gamepadButtonDurations[id][b]++