mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-23 09:22:01 +01:00
uidriver/glfw: Bug fix: Skip some special 'joysticks'
Apparently, there are some special devices that are recognized as joysticks by GLFW, even though they are not. Such devices can have too many 'buttons'. Skip them as a tentative solution. Updates #1173
This commit is contained in:
parent
b7a1e85788
commit
d08f57e610
@ -348,10 +348,26 @@ func (i *Input) update(window *glfw.Window, context driver.UIContext) {
|
|||||||
if !id.Present() {
|
if !id.Present() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
buttons := id.GetButtons()
|
||||||
|
|
||||||
|
// A gamepad can be detected even though there are not. Apparently, some special devices are
|
||||||
|
// recognized as gamepads by GLFW. In this case, the number of the 'buttons' can exceeds the
|
||||||
|
// maximum. Skip such devices as a tentative solution (#1173).
|
||||||
|
if len(buttons) > driver.GamepadButtonNum {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
i.gamepads[id].valid = true
|
i.gamepads[id].valid = true
|
||||||
// Note that GLFW's gamepad GUID follows SDL's GUID.
|
|
||||||
i.gamepads[id].guid = id.GetGUID()
|
i.gamepads[id].buttonNum = len(buttons)
|
||||||
i.gamepads[id].name = id.GetName()
|
for b := 0; b < len(i.gamepads[id].buttonPressed); b++ {
|
||||||
|
if len(buttons) <= b {
|
||||||
|
i.gamepads[id].buttonPressed[b] = false
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
i.gamepads[id].buttonPressed[b] = glfw.Action(buttons[b]) == glfw.Press
|
||||||
|
}
|
||||||
|
|
||||||
axes32 := id.GetAxes()
|
axes32 := id.GetAxes()
|
||||||
i.gamepads[id].axisNum = len(axes32)
|
i.gamepads[id].axisNum = len(axes32)
|
||||||
@ -362,15 +378,10 @@ func (i *Input) update(window *glfw.Window, context driver.UIContext) {
|
|||||||
}
|
}
|
||||||
i.gamepads[id].axes[a] = float64(axes32[a])
|
i.gamepads[id].axes[a] = float64(axes32[a])
|
||||||
}
|
}
|
||||||
buttons := id.GetButtons()
|
|
||||||
i.gamepads[id].buttonNum = len(buttons)
|
// Note that GLFW's gamepad GUID follows SDL's GUID.
|
||||||
for b := 0; b < len(i.gamepads[id].buttonPressed); b++ {
|
i.gamepads[id].guid = id.GetGUID()
|
||||||
if len(buttons) <= b {
|
i.gamepads[id].name = id.GetName()
|
||||||
i.gamepads[id].buttonPressed[b] = false
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
i.gamepads[id].buttonPressed[b] = glfw.Action(buttons[b]) == glfw.Press
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user