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 GitHub
parent 79e93d3b12
commit 0fd630100f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -137,12 +137,9 @@ func (i *inputState) update() {
for _, id := range i.gamepadIDsBuf { for _, id := range i.gamepadIDsBuf {
i.gamepadIDs[id] = struct{}{} i.gamepadIDs[id] = struct{}{}
if _, ok := i.gamepadButtonDurations[id]; !ok {
i.gamepadButtonDurations[id] = make([]int, ebiten.GamepadButtonMax+1)
}
n := ebiten.GamepadButtonNum(id) n := ebiten.GamepadButtonNum(id)
if n > int(ebiten.GamepadButtonMax)+1 { if n != len(i.gamepadButtonDurations[id]) {
n = int(ebiten.GamepadButtonMax) + 1 i.gamepadButtonDurations[id] = make([]int, n)
} }
for b := ebiten.GamepadButton(0); b < ebiten.GamepadButton(n); b++ { for b := ebiten.GamepadButton(0); b < ebiten.GamepadButton(n); b++ {
if ebiten.IsGamepadButtonPressed(id, b) { if ebiten.IsGamepadButtonPressed(id, b) {