From d4a522d9da997b1c228361104ab82a3266a4c176 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 24 Feb 2019 23:10:14 +0900 Subject: [PATCH] glfw: Bug fix: Do not pass Go's int pointer Go's int can be 64bit or 32bit, while C's int is always 32bit on Windows in Ebiten usage. For C's int argument, do not pass Go's int pointer or broken values are set. Related to #829 --- internal/glfw/glfw_windows.go | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/internal/glfw/glfw_windows.go b/internal/glfw/glfw_windows.go index 01e69e101..3cdf379bf 100644 --- a/internal/glfw/glfw_windows.go +++ b/internal/glfw/glfw_windows.go @@ -77,10 +77,11 @@ type Monitor struct { m uintptr } -func (m *Monitor) GetPos() (x, y int) { +func (m *Monitor) GetPos() (int, int) { + var x, y int32 glfwDLL.call("glfwGetMonitorPos", m.m, uintptr(unsafe.Pointer(&x)), uintptr(unsafe.Pointer(&y))) panicError() - return + return int(x), int(y) } func (m *Monitor) GetVideoMode() *VidMode { @@ -145,16 +146,18 @@ func (w *Window) GetMouseButton(button MouseButton) Action { return Action(r) } -func (w *Window) GetPos() (x, y int) { +func (w *Window) GetPos() (int, int) { + var x, y int32 glfwDLL.call("glfwGetWindowPos", w.w, uintptr(unsafe.Pointer(&x)), uintptr(unsafe.Pointer(&y))) panicError() - return + return int(x), int(y) } -func (w *Window) GetSize() (width, height int) { +func (w *Window) GetSize() (int, int) { + var width, height int32 glfwDLL.call("glfwGetWindowSize", w.w, uintptr(unsafe.Pointer(&width)), uintptr(unsafe.Pointer(&height))) panicError() - return + return int(width), int(height) } func (w *Window) MakeContextCurrent() { @@ -303,11 +306,11 @@ func CreateWindow(width, height int, title string, monitor *Monitor, share *Wind } func GetJoystickAxes(joy Joystick) []float32 { - l := 0 + var l int32 ptr := glfwDLL.call("glfwGetJoystickAxes", uintptr(joy), uintptr(unsafe.Pointer(&l))) panicError() as := make([]float32, l) - for i := 0; i < l; i++ { + for i := int32(0); i < l; i++ { as[i] = *(*float32)(unsafe.Pointer(ptr)) ptr += unsafe.Sizeof(float32(0)) } @@ -315,11 +318,11 @@ func GetJoystickAxes(joy Joystick) []float32 { } func GetJoystickButtons(joy Joystick) []byte { - l := 0 + var l int32 ptr := glfwDLL.call("glfwGetJoystickButtons", uintptr(joy), uintptr(unsafe.Pointer(&l))) panicError() bs := make([]byte, l) - for i := 0; i < l; i++ { + for i := int32(0); i < l; i++ { bs[i] = *(*byte)(unsafe.Pointer(ptr)) ptr++ } @@ -327,11 +330,11 @@ func GetJoystickButtons(joy Joystick) []byte { } func GetMonitors() []*Monitor { - l := 0 + var l int32 ptr := glfwDLL.call("glfwGetMonitors", uintptr(unsafe.Pointer(&l))) panicError() ms := make([]*Monitor, l) - for i := 0; i < l; i++ { + for i := int32(0); i < l; i++ { m := *(*unsafe.Pointer)(unsafe.Pointer(ptr)) if m != nil { ms[i] = &Monitor{uintptr(m)}