mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-26 03:38:55 +01:00
internal/glfw: Bug fix: Crash after disconnecting a gamepad on Windows (Wine)
This commit is contained in:
parent
d7bedd165a
commit
50320eeb5b
@ -338,6 +338,12 @@ func CreateWindow(width, height int, title string, monitor *Monitor, share *Wind
|
||||
func (j Joystick) GetGUID() string {
|
||||
ptr := glfwDLL.call("glfwGetJoystickGUID", uintptr(j))
|
||||
panicError()
|
||||
|
||||
// ptr can be nil after disconnecting the joystick.
|
||||
if ptr == 0 {
|
||||
return ""
|
||||
}
|
||||
|
||||
var backed [256]byte
|
||||
as := backed[:0]
|
||||
for i := int32(0); ; i++ {
|
||||
@ -355,6 +361,12 @@ func (j Joystick) GetGUID() string {
|
||||
func (j Joystick) GetName() string {
|
||||
ptr := glfwDLL.call("glfwGetJoystickName", uintptr(j))
|
||||
panicError()
|
||||
|
||||
// ptr can be nil after disconnecting the joystick.
|
||||
if ptr == 0 {
|
||||
return ""
|
||||
}
|
||||
|
||||
var backed [256]byte
|
||||
as := backed[:0]
|
||||
for i := int32(0); ; i++ {
|
||||
@ -373,6 +385,12 @@ func (j Joystick) GetAxes() []float32 {
|
||||
var l int32
|
||||
ptr := glfwDLL.call("glfwGetJoystickAxes", uintptr(j), uintptr(unsafe.Pointer(&l)))
|
||||
panicError()
|
||||
|
||||
// ptr can be nil after disconnecting the joystick.
|
||||
if ptr == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
as := make([]float32, l)
|
||||
for i := int32(0); i < l; i++ {
|
||||
as[i] = *(*float32)(unsafe.Pointer(ptr))
|
||||
@ -385,6 +403,12 @@ func (j Joystick) GetButtons() []byte {
|
||||
var l int32
|
||||
ptr := glfwDLL.call("glfwGetJoystickButtons", uintptr(j), uintptr(unsafe.Pointer(&l)))
|
||||
panicError()
|
||||
|
||||
// ptr can be nil after disconnecting the joystick.
|
||||
if ptr == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
bs := make([]byte, l)
|
||||
for i := int32(0); i < l; i++ {
|
||||
bs[i] = *(*byte)(unsafe.Pointer(ptr))
|
||||
@ -397,6 +421,12 @@ func (j Joystick) GetHats() []JoystickHatState {
|
||||
var l int32
|
||||
ptr := glfwDLL.call("glfwGetJoystickHats", uintptr(j), uintptr(unsafe.Pointer(&l)))
|
||||
panicError()
|
||||
|
||||
// ptr can be nil after disconnecting the joystick.
|
||||
if ptr == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
hats := make([]JoystickHatState, l)
|
||||
for i := int32(0); i < l; i++ {
|
||||
hats[i] = *(*JoystickHatState)(unsafe.Pointer(ptr))
|
||||
|
Loading…
Reference in New Issue
Block a user