inpututil: bug fix: GamepadButtonNum can exceed GamepadButtonMax

Closes #2027
This commit is contained in:
Hajime Hoshi 2022-03-25 14:31:07 +09:00
parent b985689010
commit 5bb22d2bcf

View File

@ -141,6 +141,9 @@ func (i *inputState) update() {
i.gamepadButtonDurations[id] = make([]int, ebiten.GamepadButtonMax+1)
}
n := ebiten.GamepadButtonNum(id)
if n > ebiten.GamepadButtonMax+1 {
n = ebiten.GamepadButtonMax + 1
}
for b := ebiten.GamepadButton(0); b < ebiten.GamepadButton(n); b++ {
if ebiten.IsGamepadButtonPressed(id, b) {
i.gamepadButtonDurations[id][b]++