The following error occurs when running a blank application (nothing drawn/updated) on the latest master (likely caused by c95049b).
panic: runtime error: index out of range [32] with length 32
goroutine 5 [running]:
github.com/hajimehoshi/ebiten/inpututil.(*inputState).update(0xb50f20)
/home/trevor/go/pkg/mod/github.com/hajimehoshi/[email protected]/inpututil/inpututil.go:122 +0xdc6
github.com/hajimehoshi/ebiten/inpututil.init.0.func1(0x0, 0x0)
/home/trevor/go/pkg/mod/github.com/hajimehoshi/[email protected]/inpututil/inpututil.go:64 +0x2d
github.com/hajimehoshi/ebiten/internal/hooks.RunBeforeUpdateHooks(0x0, 0x0)
/home/trevor/go/pkg/mod/github.com/hajimehoshi/[email protected]/internal/hooks/hooks.go:38 +0xb8
github.com/hajimehoshi/ebiten.(*uiContext).update(0xb50d20, 0x0, 0x0)
/home/trevor/go/pkg/mod/github.com/hajimehoshi/[email protected]/uicontext.go:287 +0xe7
github.com/hajimehoshi/ebiten.(*uiContext).Update(0xb50d20, 0xc00005de10, 0x8d0000)
/home/trevor/go/pkg/mod/github.com/hajimehoshi/[email protected]/uicontext.go:241 +0xaa
github.com/hajimehoshi/ebiten/internal/uidriver/glfw.(*UserInterface).update(0xb132e0, 0x20001, 0x1)
/home/trevor/go/pkg/mod/github.com/hajimehoshi/[email protected]/internal/uidriver/glfw/ui.go:816 +0x266
github.com/hajimehoshi/ebiten/internal/uidriver/glfw.(*UserInterface).loop(0xb132e0, 0x0, 0x0)
/home/trevor/go/pkg/mod/github.com/hajimehoshi/[email protected]/internal/uidriver/glfw/ui.go:862 +0xcb
github.com/hajimehoshi/ebiten/internal/uidriver/glfw.(*UserInterface).run(0xb132e0, 0x0, 0x0)
/home/trevor/go/pkg/mod/github.com/hajimehoshi/[email protected]/internal/uidriver/glfw/ui.go:731 +0x2e4
github.com/hajimehoshi/ebiten/internal/uidriver/glfw.(*UserInterface).Run.func1(0xc000098410, 0xc0000b4180, 0xb132e0)
/home/trevor/go/pkg/mod/github.com/hajimehoshi/[email protected]/internal/uidriver/glfw/ui.go:568 +0x6b
created by github.com/hajimehoshi/ebiten/internal/uidriver/glfw.(*UserInterface).Run
/home/trevor/go/pkg/mod/github.com/hajimehoshi/[email protected]/internal/uidriver/glfw/ui.go:565 +0x17b
Sorry for the noise, I have found that this panic was my fault and not ebiten's. (I initialized two games)
Hmmmm, I still seem to be encountering this after resolving other issues. You can reproduce this by running gitlab.com/tslocum/venture/cmd/venturedemo.
I'll take a look.
CC @seebs
What kind of gamepad are you using now?
Thanks. I don't have any gamepads connected. And in case it helps this is was encountered on Gentoo Linux + Sway (Wayland).
The error indicates that ebiten.GamepadIDs() returns a slice of IDs, which indicates there is a gamepad on your machine. That's pretty odd. Could you try ebiten.GamepadIDs() and see what IDs are there?
I tested the app on macOS and could not reproduce the same error.
This is odd, because the max gamepad button ID in the code is 31, so I was assuming that [32] would be right?
I think getting the number of the gamepad buttons returns >32. This might be an issue in GLFW.
Thanks. ebiten.GamepadIDs() returns an empty slice on my machine when added to the above demo.
okay, looking at it, there's at least something in my code which is probably logically-wrong:
n := ebiten.GamepadButtonNum(id)
this isn't capped in any way as being less than the listed Max, so. I'll send a possible patch, but since I can't reproduce the failure myself yet, I don't know whether it's sane.
Thanks. ebiten.GamepadIDs() returns an empty slice on my machine when added to the above demo.
Thanks. If so, inpututil.go:122 should never be reached. Am I missing something? 馃
So, I was wondering whether ebiten.GamepadIDs() is deterministic and always 0 or not.
Found the same bug when running on windows.

Yeah, I know how to suppress the error. My question is why a gamepad is detected even though there is no actual gamepad device.
@cesys So, have you reproduced the same error without a gamepad?
In my case, there was no gamepad active (they were all not paired) but I have XBox controllers paired with my Windows (again turned off when I ran the test). I wonder if they are detected as gamepads because the receiver is actually plugged in the USB port or that's because of another device I have plugged that is seen as a gamepad. Not sure.
I see. Even though the XBox gamepad is connected, I don't think the XBox gamepad has more than 32 buttons. Actually the screenshot says n = 1085 buttons, right?
Yeah definitely not 32 buttons. No idea why we get 1085 (either a bug triggered by some peripherals I have or a weird value returned by some peripheral I have). However, adding that check in this specific case should be good anyway and should fix this problem
Thanks. Before patching this, I'd like to check whether the root cause was in Ebiten or in GLFW. If GLFW is the cause (and I think this is true but am not sure yet), I'd be happy to patch this.
The same issue is reported by another person. I'll take a look...
My guess is that there are some devices that are not joysticks but recognized as joysticks by GLFW.
I think this was fixed.
@tslocum , @cesys Could you test when you are available? Thanks!
Ripolak from OpenDiablo 2 Discord tested this and confirmed this was fixed.
Most helpful comment
Sorry for the noise, I have found that this panic was my fault and not ebiten's. (I initialized two games)