From 1de1bfef55f54767e2ef4fc4c96a9de71a46ef8c Mon Sep 17 00:00:00 2001 From: divVerent Date: Sat, 26 Mar 2022 02:41:59 -0400 Subject: [PATCH] internal/gamepad: fix uint16 underflow handling in gamepads. (#2030) Fixes crash where Ebiten considers a keyboard a gamepad with way too many buttons. Updates #2027 --- internal/gamepad/gamepad_linux.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/gamepad/gamepad_linux.go b/internal/gamepad/gamepad_linux.go index 5a338f6fa..64b53ad28 100644 --- a/internal/gamepad/gamepad_linux.go +++ b/internal/gamepad/gamepad_linux.go @@ -328,7 +328,7 @@ func (g *nativeGamepad) update(gamepad *gamepads) error { switch e.typ { case unix.EV_KEY: - if int(e.code)-_BTN_MISC < len(g.keyMap) { + if int(e.code-_BTN_MISC) < len(g.keyMap) { idx := g.keyMap[e.code-_BTN_MISC] g.buttons[idx] = e.value != 0 }