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
This commit is contained in:
divVerent 2022-03-26 07:25:41 -04:00 committed by Hajime Hoshi
parent e583d28a82
commit 700d478665

View File

@ -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) {