From ee15e06c50972aa8269e757693d8c78e72ba47d9 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Fri, 4 Sep 2020 01:10:39 +0900 Subject: [PATCH] glfw: Remove some suspicious codes depending on the memory layout --- internal/glfw/glfw_windows.go | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/internal/glfw/glfw_windows.go b/internal/glfw/glfw_windows.go index 9229c3151..f1b83bede 100644 --- a/internal/glfw/glfw_windows.go +++ b/internal/glfw/glfw_windows.go @@ -24,15 +24,6 @@ import ( "golang.org/x/sys/windows" ) -type glfwVidMode struct { - width int32 - height int32 - redBits int32 - greenBits int32 - blueBits int32 - refreshRate int32 -} - type glfwImage struct { width int32 height int32 @@ -87,14 +78,13 @@ func (m *Monitor) GetPos() (int, int) { func (m *Monitor) GetVideoMode() *VidMode { v := glfwDLL.call("glfwGetVideoMode", m.m) panicError() - vv := (*glfwVidMode)(unsafe.Pointer(v)) return &VidMode{ - Width: int(vv.width), - Height: int(vv.height), - RedBits: int(vv.redBits), - GreenBits: int(vv.greenBits), - BlueBits: int(vv.blueBits), - RefreshRate: int(vv.refreshRate), + Width: int(*(*int32)(unsafe.Pointer(v))), + Height: int(*(*int32)(unsafe.Pointer(v + 4))), + RedBits: int(*(*int32)(unsafe.Pointer(v + 8))), + GreenBits: int(*(*int32)(unsafe.Pointer(v + 12))), + BlueBits: int(*(*int32)(unsafe.Pointer(v + 16))), + RefreshRate: int(*(*int32)(unsafe.Pointer(v + 20))), } }