From 80056827862b702b2999717fa3651bf47b13704d Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Wed, 3 Apr 2019 11:53:20 +0900 Subject: [PATCH] devicescale: Use runtime.KeepAlive for Windows This might be related to the bug #832 --- internal/devicescale/impl_windows.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/internal/devicescale/impl_windows.go b/internal/devicescale/impl_windows.go index 3aeadb500..e71c9867e 100644 --- a/internal/devicescale/impl_windows.go +++ b/internal/devicescale/impl_windows.go @@ -18,6 +18,7 @@ package devicescale import ( "fmt" + "runtime" "unsafe" "golang.org/x/sys/windows" @@ -136,8 +137,9 @@ func getDeviceCaps(hdc uintptr, nindex int) (int, error) { return int(r), nil } -func monitorFromRect(lprc uintptr, dwFlags int) (uintptr, error) { - r, _, e := procMonitorFromRect.Call(lprc, uintptr(dwFlags)) +func monitorFromRect(lprc *rect, dwFlags int) (uintptr, error) { + r, _, e := procMonitorFromRect.Call(uintptr(unsafe.Pointer(lprc)), uintptr(dwFlags)) + runtime.KeepAlive(lprc) if e != nil && e.(windows.Errno) != 0 { return 0, &winErr{ FuncName: "MonitorFromRect", @@ -238,7 +240,7 @@ func impl(x, y int) float64 { // MonitorFromPoint requires to pass a POINT value, and there seems no portable way to // do this with Cgo. Use MonitorFromRect instead. - m, err := monitorFromRect(uintptr(unsafe.Pointer(&lprc)), monitorDefaultToNearest) + m, err := monitorFromRect(&lprc, monitorDefaultToNearest) if err != nil { panic(err) }