internal/glfwwin, internal/graphicsdriver/directx: bug fix: wrong error handlings for Windows HANDLE

Closes #2366
This commit is contained in:
Hajime Hoshi 2022-10-02 01:52:21 +09:00
parent f6c4b29a3d
commit a9ba0db3d1
3 changed files with 17 additions and 5 deletions

View File

@ -24,6 +24,12 @@ import (
"golang.org/x/sys/windows" "golang.org/x/sys/windows"
) )
type handleError windows.Handle
func (h handleError) Error() string {
return fmt.Sprintf("HANDLE(%d)", h)
}
// math.MaxUint was added at Go 1.17. See https://github.com/golang/go/issues/28538 // math.MaxUint was added at Go 1.17. See https://github.com/golang/go/issues/28538
const ( const (
intSize = 32 << (^uint(0) >> 63) intSize = 32 << (^uint(0) >> 63)
@ -1312,7 +1318,7 @@ func _GetMonitorInfoW_Ex(hMonitor _HMONITOR) (_MONITORINFOEXW, bool) {
func _GetDpiForMonitor(hmonitor _HMONITOR, dpiType _MONITOR_DPI_TYPE) (dpiX, dpiY uint32, err error) { func _GetDpiForMonitor(hmonitor _HMONITOR, dpiType _MONITOR_DPI_TYPE) (dpiX, dpiY uint32, err error) {
r, _, _ := procGetDpiForMonitor.Call(uintptr(hmonitor), uintptr(dpiType), uintptr(unsafe.Pointer(&dpiX)), uintptr(unsafe.Pointer(&dpiY))) r, _, _ := procGetDpiForMonitor.Call(uintptr(hmonitor), uintptr(dpiType), uintptr(unsafe.Pointer(&dpiX)), uintptr(unsafe.Pointer(&dpiY)))
if uint32(r) != uint32(windows.S_OK) { if uint32(r) != uint32(windows.S_OK) {
return 0, 0, fmt.Errorf("glfwwin: GetDpiForMonitor failed: %w", windows.Errno(uint32(r))) return 0, 0, fmt.Errorf("glfwwin: GetDpiForMonitor failed: %w", handleError(windows.Handle(uint32(r))))
} }
return dpiX, dpiY, nil return dpiX, dpiY, nil
} }
@ -1593,7 +1599,7 @@ func _SetProcessDPIAware() bool {
func _SetProcessDpiAwareness(value _PROCESS_DPI_AWARENESS) error { func _SetProcessDpiAwareness(value _PROCESS_DPI_AWARENESS) error {
r, _, _ := procSetProcessDpiAwareness.Call(uintptr(value)) r, _, _ := procSetProcessDpiAwareness.Call(uintptr(value))
if uint32(r) != uint32(windows.S_OK) { if uint32(r) != uint32(windows.S_OK) {
return fmt.Errorf("glfwwin: SetProcessDpiAwareness failed: %w", windows.Errno(uint32(r))) return fmt.Errorf("glfwwin: SetProcessDpiAwareness failed: %w", handleError(windows.Handle(uint32(r))))
} }
return nil return nil
} }

View File

@ -246,7 +246,7 @@ func platformInit() error {
_ = _SetProcessDpiAwarenessContext(_DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2) _ = _SetProcessDpiAwarenessContext(_DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2)
} }
} else if _IsWindows8Point1OrGreater() { } else if _IsWindows8Point1OrGreater() {
if err := _SetProcessDpiAwareness(_PROCESS_PER_MONITOR_DPI_AWARE); err != nil && !errors.Is(err, windows.ERROR_ACCESS_DENIED) { if err := _SetProcessDpiAwareness(_PROCESS_PER_MONITOR_DPI_AWARE); err != nil && !errors.Is(err, handleError(windows.E_ACCESSDENIED)) {
return err return err
} }
} else if _IsWindowsVistaOrGreater() { } else if _IsWindowsVistaOrGreater() {

View File

@ -29,6 +29,12 @@ import (
const is64bit = unsafe.Sizeof(uintptr(0)) == 8 const is64bit = unsafe.Sizeof(uintptr(0)) == 8
type handleError windows.Handle
func (h handleError) Error() string {
return fmt.Sprintf("HANDLE(%d)", h)
}
type ( type (
_BOOL int32 _BOOL int32
) )
@ -639,7 +645,7 @@ const (
_DXGI_CREATE_FACTORY_DEBUG = 0x01 _DXGI_CREATE_FACTORY_DEBUG = 0x01
_DXGI_ERROR_NOT_FOUND = windows.Errno(0x887A0002) _DXGI_ERROR_NOT_FOUND = handleError(0x887A0002)
_DXGI_MWA_NO_ALT_ENTER = 0x2 _DXGI_MWA_NO_ALT_ENTER = 0x2
_DXGI_MWA_NO_WINDOW_CHANGES = 0x1 _DXGI_MWA_NO_WINDOW_CHANGES = 0x1
@ -2464,7 +2470,7 @@ func (i *_IDXGIFactory4) EnumAdapters1(adapter uint32) (*_IDXGIAdapter1, error)
var ptr *_IDXGIAdapter1 var ptr *_IDXGIAdapter1
r, _, _ := syscall.Syscall(i.vtbl.EnumAdapters1, 3, uintptr(unsafe.Pointer(i)), uintptr(adapter), uintptr(unsafe.Pointer(&ptr))) r, _, _ := syscall.Syscall(i.vtbl.EnumAdapters1, 3, uintptr(unsafe.Pointer(i)), uintptr(adapter), uintptr(unsafe.Pointer(&ptr)))
if uint32(r) != uint32(windows.S_OK) { if uint32(r) != uint32(windows.S_OK) {
return nil, fmt.Errorf("directx: IDXGIFactory4::EnumAdapters1 failed: HRESULT(%d)", uint32(r)) return nil, fmt.Errorf("directx: IDXGIFactory4::EnumAdapters1 failed: %w", handleError(windows.Handle(uint32(r))))
} }
return ptr, nil return ptr, nil
} }