all: unify Windows error handlings for Windows HANDLE

Updates #2366
This commit is contained in:
Hajime Hoshi 2022-10-02 02:09:04 +09:00
parent a9ba0db3d1
commit 8a7d860632
6 changed files with 70 additions and 70 deletions

View File

@ -206,12 +206,6 @@ func _SetWindowLongPtrW(hWnd windows.HWND, nIndex int32, dwNewLong uintptr) (uin
return h, nil return h, nil
} }
type directInputError uint32
func (d directInputError) Error() string {
return fmt.Sprintf("DirectInput error: HRESULT(%d)", d)
}
type _DIDATAFORMAT struct { type _DIDATAFORMAT struct {
dwSize uint32 dwSize uint32
dwObjSize uint32 dwObjSize uint32
@ -327,7 +321,7 @@ func (d *_IDirectInput8W) CreateDevice(rguid *windows.GUID, lplpDirectInputDevic
uintptr(unsafe.Pointer(rguid)), uintptr(unsafe.Pointer(lplpDirectInputDevice)), uintptr(pUnkOuter), uintptr(unsafe.Pointer(rguid)), uintptr(unsafe.Pointer(lplpDirectInputDevice)), uintptr(pUnkOuter),
0, 0) 0, 0)
if uint32(r) != _DI_OK { if uint32(r) != _DI_OK {
return fmt.Errorf("gamepad: IDirectInput8::CreateDevice failed: %w", directInputError(r)) return fmt.Errorf("gamepad: IDirectInput8::CreateDevice failed: %w", handleError(windows.Handle(uint32(r))))
} }
return nil return nil
} }
@ -338,7 +332,7 @@ func (d *_IDirectInput8W) EnumDevices(dwDevType uint32, lpCallback uintptr, pvRe
uintptr(dwDevType), lpCallback, uintptr(pvRef), uintptr(dwFlags), uintptr(dwDevType), lpCallback, uintptr(pvRef), uintptr(dwFlags),
0) 0)
if uint32(r) != _DI_OK { if uint32(r) != _DI_OK {
return fmt.Errorf("gamepad: IDirectInput8::EnumDevices failed: %w", directInputError(r)) return fmt.Errorf("gamepad: IDirectInput8::EnumDevices failed: %w", handleError(windows.Handle(uint32(r))))
} }
return nil return nil
} }
@ -386,7 +380,7 @@ type _IDirectInputDevice8W_Vtbl struct {
func (d *_IDirectInputDevice8W) Acquire() error { func (d *_IDirectInputDevice8W) Acquire() error {
r, _, _ := syscall.Syscall(d.vtbl.Acquire, 1, uintptr(unsafe.Pointer(d)), 0, 0) r, _, _ := syscall.Syscall(d.vtbl.Acquire, 1, uintptr(unsafe.Pointer(d)), 0, 0)
if uint32(r) != _DI_OK && uint32(r) != _SI_FALSE { if uint32(r) != _DI_OK && uint32(r) != _SI_FALSE {
return fmt.Errorf("gamepad: IDirectInputDevice8::Acquire failed: %w", directInputError(r)) return fmt.Errorf("gamepad: IDirectInputDevice8::Acquire failed: %w", handleError(windows.Handle(uint32(r))))
} }
return nil return nil
} }
@ -397,7 +391,7 @@ func (d *_IDirectInputDevice8W) EnumObjects(lpCallback uintptr, pvRef unsafe.Poi
lpCallback, uintptr(pvRef), uintptr(dwFlags), lpCallback, uintptr(pvRef), uintptr(dwFlags),
0, 0) 0, 0)
if uint32(r) != _DI_OK { if uint32(r) != _DI_OK {
return fmt.Errorf("gamepad: IDirectInputDevice8::EnumObjects failed: %w", directInputError(r)) return fmt.Errorf("gamepad: IDirectInputDevice8::EnumObjects failed: %w", handleError(windows.Handle(uint32(r))))
} }
return nil return nil
} }
@ -405,7 +399,7 @@ func (d *_IDirectInputDevice8W) EnumObjects(lpCallback uintptr, pvRef unsafe.Poi
func (d *_IDirectInputDevice8W) GetCapabilities(lpDIDevCaps *_DIDEVCAPS) error { func (d *_IDirectInputDevice8W) GetCapabilities(lpDIDevCaps *_DIDEVCAPS) error {
r, _, _ := syscall.Syscall(d.vtbl.GetCapabilities, 2, uintptr(unsafe.Pointer(d)), uintptr(unsafe.Pointer(lpDIDevCaps)), 0) r, _, _ := syscall.Syscall(d.vtbl.GetCapabilities, 2, uintptr(unsafe.Pointer(d)), uintptr(unsafe.Pointer(lpDIDevCaps)), 0)
if uint32(r) != _DI_OK { if uint32(r) != _DI_OK {
return fmt.Errorf("gamepad: IDirectInputDevice8::GetCapabilities failed: %w", directInputError(r)) return fmt.Errorf("gamepad: IDirectInputDevice8::GetCapabilities failed: %w", handleError(windows.Handle(uint32(r))))
} }
return nil return nil
} }
@ -413,7 +407,7 @@ func (d *_IDirectInputDevice8W) GetCapabilities(lpDIDevCaps *_DIDEVCAPS) error {
func (d *_IDirectInputDevice8W) GetDeviceState(cbData uint32, lpvData unsafe.Pointer) error { func (d *_IDirectInputDevice8W) GetDeviceState(cbData uint32, lpvData unsafe.Pointer) error {
r, _, _ := syscall.Syscall(d.vtbl.GetDeviceState, 3, uintptr(unsafe.Pointer(d)), uintptr(cbData), uintptr(lpvData)) r, _, _ := syscall.Syscall(d.vtbl.GetDeviceState, 3, uintptr(unsafe.Pointer(d)), uintptr(cbData), uintptr(lpvData))
if uint32(r) != _DI_OK { if uint32(r) != _DI_OK {
return fmt.Errorf("gamepad: IDirectInputDevice8::GetDeviceState failed: %w", directInputError(r)) return fmt.Errorf("gamepad: IDirectInputDevice8::GetDeviceState failed: %w", handleError(windows.Handle(uint32(r))))
} }
return nil return nil
} }
@ -421,7 +415,7 @@ func (d *_IDirectInputDevice8W) GetDeviceState(cbData uint32, lpvData unsafe.Poi
func (d *_IDirectInputDevice8W) Poll() error { func (d *_IDirectInputDevice8W) Poll() error {
r, _, _ := syscall.Syscall(d.vtbl.Poll, 1, uintptr(unsafe.Pointer(d)), 0, 0) r, _, _ := syscall.Syscall(d.vtbl.Poll, 1, uintptr(unsafe.Pointer(d)), 0, 0)
if uint32(r) != _DI_OK && uint32(r) != _DI_NOEFFECT { if uint32(r) != _DI_OK && uint32(r) != _DI_NOEFFECT {
return fmt.Errorf("gamepad: IDirectInputDevice8::Poll failed: %w", directInputError(r)) return fmt.Errorf("gamepad: IDirectInputDevice8::Poll failed: %w", handleError(windows.Handle(uint32(r))))
} }
return nil return nil
} }
@ -434,7 +428,7 @@ func (d *_IDirectInputDevice8W) Release() uint32 {
func (d *_IDirectInputDevice8W) SetDataFormat(lpdf *_DIDATAFORMAT) error { func (d *_IDirectInputDevice8W) SetDataFormat(lpdf *_DIDATAFORMAT) error {
r, _, _ := syscall.Syscall(d.vtbl.SetDataFormat, 2, uintptr(unsafe.Pointer(d)), uintptr(unsafe.Pointer(lpdf)), 0) r, _, _ := syscall.Syscall(d.vtbl.SetDataFormat, 2, uintptr(unsafe.Pointer(d)), uintptr(unsafe.Pointer(lpdf)), 0)
if uint32(r) != _DI_OK { if uint32(r) != _DI_OK {
return fmt.Errorf("gamepad: IDirectInputDevice8::SetDataFormat failed: %w", directInputError(r)) return fmt.Errorf("gamepad: IDirectInputDevice8::SetDataFormat failed: %w", handleError(windows.Handle(uint32(r))))
} }
return nil return nil
} }
@ -442,7 +436,7 @@ func (d *_IDirectInputDevice8W) SetDataFormat(lpdf *_DIDATAFORMAT) error {
func (d *_IDirectInputDevice8W) SetProperty(rguidProp uintptr, pdiph *_DIPROPHEADER) error { func (d *_IDirectInputDevice8W) SetProperty(rguidProp uintptr, pdiph *_DIPROPHEADER) error {
r, _, _ := syscall.Syscall(d.vtbl.SetProperty, 3, uintptr(unsafe.Pointer(d)), rguidProp, uintptr(unsafe.Pointer(pdiph))) r, _, _ := syscall.Syscall(d.vtbl.SetProperty, 3, uintptr(unsafe.Pointer(d)), rguidProp, uintptr(unsafe.Pointer(pdiph)))
if uint32(r) != _DI_OK && uint32(r) != _DI_PROPNOEFFECT { if uint32(r) != _DI_OK && uint32(r) != _DI_PROPNOEFFECT {
return fmt.Errorf("gamepad: IDirectInputDevice8::SetProperty failed: %w", directInputError(r)) return fmt.Errorf("gamepad: IDirectInputDevice8::SetProperty failed: %w", handleError(windows.Handle(uint32(r))))
} }
return nil return nil
} }

View File

@ -26,6 +26,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)
}
var ( var (
gameInput = windows.NewLazySystemDLL("GameInput.dll") gameInput = windows.NewLazySystemDLL("GameInput.dll")
@ -120,7 +126,7 @@ func _GameInputCreate() (*_IGameInput, error) {
var gameInput *_IGameInput var gameInput *_IGameInput
r, _, _ := procGameInputCreate.Call(uintptr(unsafe.Pointer(&gameInput))) r, _, _ := procGameInputCreate.Call(uintptr(unsafe.Pointer(&gameInput)))
if uint32(r) != uint32(windows.S_OK) { if uint32(r) != uint32(windows.S_OK) {
return nil, fmt.Errorf("gamepad: GameInputCreate failed: HRESULT(%d)", uint32(r)) return nil, fmt.Errorf("gamepad: GameInputCreate failed: %w", handleError(windows.Handle(uint32(r))))
} }
return gameInput, nil return gameInput, nil
} }
@ -162,7 +168,7 @@ func (i *_IGameInput) GetCurrentReading(inputKind _GameInputKind, device *_IGame
0, 0) 0, 0)
runtime.KeepAlive(device) runtime.KeepAlive(device)
if uint32(r) != uint32(windows.S_OK) { if uint32(r) != uint32(windows.S_OK) {
return nil, fmt.Errorf("gamepad: IGameInput::GetCurrentReading failed: HRESULT(%d)", uint32(r)) return nil, fmt.Errorf("gamepad: IGameInput::GetCurrentReading failed: %w", handleError(windows.Handle(uint32(r))))
} }
return reading, nil return reading, nil
} }
@ -181,7 +187,7 @@ func (i *_IGameInput) RegisterDeviceCallback(device *_IGameInputDevice,
runtime.KeepAlive(device) runtime.KeepAlive(device)
runtime.KeepAlive(callbackToken) runtime.KeepAlive(callbackToken)
if uint32(r) != uint32(windows.S_OK) { if uint32(r) != uint32(windows.S_OK) {
return fmt.Errorf("gamepad: IGameInput::RegisterDeviceCallback failed: HRESULT(%d)", uint32(r)) return fmt.Errorf("gamepad: IGameInput::RegisterDeviceCallback failed: %w", handleError(windows.Handle(uint32(r))))
} }
return nil return nil
} }

View File

@ -202,7 +202,7 @@ func (g *nativeGamepadsDesktop) directInput8Create(hinst uintptr, dwVersion uint
hinst, uintptr(dwVersion), uintptr(unsafe.Pointer(riidltf)), uintptr(unsafe.Pointer(ppvOut)), uintptr(punkOuter), hinst, uintptr(dwVersion), uintptr(unsafe.Pointer(riidltf)), uintptr(unsafe.Pointer(ppvOut)), uintptr(punkOuter),
0) 0)
if uint32(r) != _DI_OK { if uint32(r) != _DI_OK {
return fmt.Errorf("gamepad: DirectInput8Create failed: %w", directInputError(r)) return fmt.Errorf("gamepad: DirectInput8Create failed: %w", handleError(windows.Handle(uint32(r))))
} }
return nil return nil
} }
@ -601,25 +601,25 @@ func (g *nativeGamepadDesktop) update(gamepads *gamepads) (err error) {
if g.usesDInput() { if g.usesDInput() {
if err := g.dinputDevice.Poll(); err != nil { if err := g.dinputDevice.Poll(); err != nil {
if !errors.Is(err, directInputError(_DIERR_NOTACQUIRED)) && !errors.Is(err, directInputError(_DIERR_INPUTLOST)) { if !errors.Is(err, handleError(_DIERR_NOTACQUIRED)) && !errors.Is(err, handleError(_DIERR_INPUTLOST)) {
return err return err
} }
} }
var state _DIJOYSTATE var state _DIJOYSTATE
if err := g.dinputDevice.GetDeviceState(uint32(unsafe.Sizeof(state)), unsafe.Pointer(&state)); err != nil { if err := g.dinputDevice.GetDeviceState(uint32(unsafe.Sizeof(state)), unsafe.Pointer(&state)); err != nil {
if !errors.Is(err, directInputError(_DIERR_NOTACQUIRED)) && !errors.Is(err, directInputError(_DIERR_INPUTLOST)) { if !errors.Is(err, handleError(_DIERR_NOTACQUIRED)) && !errors.Is(err, handleError(_DIERR_INPUTLOST)) {
return err return err
} }
// Acquire can return an error just after a gamepad is disconnected. Ignore the error. // Acquire can return an error just after a gamepad is disconnected. Ignore the error.
_ = g.dinputDevice.Acquire() _ = g.dinputDevice.Acquire()
if err := g.dinputDevice.Poll(); err != nil { if err := g.dinputDevice.Poll(); err != nil {
if !errors.Is(err, directInputError(_DIERR_NOTACQUIRED)) && !errors.Is(err, directInputError(_DIERR_INPUTLOST)) { if !errors.Is(err, handleError(_DIERR_NOTACQUIRED)) && !errors.Is(err, handleError(_DIERR_INPUTLOST)) {
return err return err
} }
} }
if err := g.dinputDevice.GetDeviceState(uint32(unsafe.Sizeof(state)), unsafe.Pointer(&state)); err != nil { if err := g.dinputDevice.GetDeviceState(uint32(unsafe.Sizeof(state)), unsafe.Pointer(&state)); err != nil {
if !errors.Is(err, directInputError(_DIERR_NOTACQUIRED)) && !errors.Is(err, directInputError(_DIERR_INPUTLOST)) { if !errors.Is(err, handleError(_DIERR_NOTACQUIRED)) && !errors.Is(err, handleError(_DIERR_INPUTLOST)) {
return err return err
} }
disconnected = true disconnected = true

View File

@ -1079,7 +1079,7 @@ func _DragQueryPoint(hDrop _HDROP) (_POINT, bool) {
func _DwmEnableBlurBehindWindow(hWnd windows.HWND, pBlurBehind *_DWM_BLURBEHIND) error { func _DwmEnableBlurBehindWindow(hWnd windows.HWND, pBlurBehind *_DWM_BLURBEHIND) error {
r, _, _ := procDwmEnableBlurBehindWindow.Call(uintptr(hWnd), uintptr(unsafe.Pointer(pBlurBehind))) r, _, _ := procDwmEnableBlurBehindWindow.Call(uintptr(hWnd), uintptr(unsafe.Pointer(pBlurBehind)))
if uint32(r) != uint32(windows.S_OK) { if uint32(r) != uint32(windows.S_OK) {
return fmt.Errorf("glfwwin: DwmEnableBlurBehindWindow failed: HRESULT(%d)", uint32(r)) return fmt.Errorf("glfwwin: DwmEnableBlurBehindWindow failed: %w", handleError(windows.Handle(uint32(r))))
} }
return nil return nil
} }
@ -1089,7 +1089,7 @@ func _DwmGetColorizationColor() (uint32, bool, error) {
var opaqueBlend int32 var opaqueBlend int32
r, _, _ := procDwmGetColorizationColor.Call(uintptr(unsafe.Pointer(&colorization)), uintptr(unsafe.Pointer(&opaqueBlend))) r, _, _ := procDwmGetColorizationColor.Call(uintptr(unsafe.Pointer(&colorization)), uintptr(unsafe.Pointer(&opaqueBlend)))
if uint32(r) != uint32(windows.S_OK) { if uint32(r) != uint32(windows.S_OK) {
return 0, false, fmt.Errorf("glfwwin: DwmGetColorizationColor failed: HRESULT(%d)", uint32(r)) return 0, false, fmt.Errorf("glfwwin: DwmGetColorizationColor failed: %w", handleError(windows.Handle(uint32(r))))
} }
return colorization, opaqueBlend != 0, nil return colorization, opaqueBlend != 0, nil
} }
@ -1097,7 +1097,7 @@ func _DwmGetColorizationColor() (uint32, bool, error) {
func _DwmFlush() error { func _DwmFlush() error {
r, _, _ := procDwmFlush.Call() r, _, _ := procDwmFlush.Call()
if uint32(r) != uint32(windows.S_OK) { if uint32(r) != uint32(windows.S_OK) {
return fmt.Errorf("glfwwin: DwmFlush failed: HRESULT(%d)", uint32(r)) return fmt.Errorf("glfwwin: DwmFlush failed: %w", handleError(windows.Handle(uint32(r))))
} }
return nil return nil
} }
@ -1106,7 +1106,7 @@ func _DwmIsCompositionEnabled() (bool, error) {
var enabled int32 var enabled int32
r, _, _ := procDwmIsCompositionEnabled.Call(uintptr(unsafe.Pointer(&enabled))) r, _, _ := procDwmIsCompositionEnabled.Call(uintptr(unsafe.Pointer(&enabled)))
if uint32(r) != uint32(windows.S_OK) { if uint32(r) != uint32(windows.S_OK) {
return false, fmt.Errorf("glfwwin: DwmIsCompositionEnabled failed: HRESULT(%d)", uint32(r)) return false, fmt.Errorf("glfwwin: DwmIsCompositionEnabled failed: %w", handleError(windows.Handle(uint32(r))))
} }
return enabled != 0, nil return enabled != 0, nil
} }

View File

@ -1037,10 +1037,10 @@ func _D3D12CreateDevice(pAdapter unsafe.Pointer, minimumFeatureLevel _D3D_FEATUR
} }
r, _, _ := procD3D12CreateDevice.Call(uintptr(pAdapter), uintptr(minimumFeatureLevel), uintptr(unsafe.Pointer(riid)), uintptr(unsafe.Pointer(pv))) r, _, _ := procD3D12CreateDevice.Call(uintptr(pAdapter), uintptr(minimumFeatureLevel), uintptr(unsafe.Pointer(riid)), uintptr(unsafe.Pointer(pv)))
if v == nil && uint32(r) != uint32(windows.S_FALSE) { if v == nil && uint32(r) != uint32(windows.S_FALSE) {
return nil, fmt.Errorf("directx: D3D12CreateDevice failed: HRESULT(%d)", uint32(r)) return nil, fmt.Errorf("directx: D3D12CreateDevice failed: %w", handleError(windows.Handle(uint32(r))))
} }
if v != nil && uint32(r) != uint32(windows.S_OK) { if v != nil && uint32(r) != uint32(windows.S_OK) {
return nil, fmt.Errorf("directx: D3D12CreateDevice failed: HRESULT(%d)", uint32(r)) return nil, fmt.Errorf("directx: D3D12CreateDevice failed: %w", handleError(windows.Handle(uint32(r))))
} }
return v, nil return v, nil
} }
@ -1049,7 +1049,7 @@ func _D3D12GetDebugInterface() (*_ID3D12Debug, error) {
var debug *_ID3D12Debug var debug *_ID3D12Debug
r, _, _ := procD3D12GetDebugInterface.Call(uintptr(unsafe.Pointer(&_IID_ID3D12Debug)), uintptr(unsafe.Pointer(&debug))) r, _, _ := procD3D12GetDebugInterface.Call(uintptr(unsafe.Pointer(&_IID_ID3D12Debug)), uintptr(unsafe.Pointer(&debug)))
if uint32(r) != uint32(windows.S_OK) { if uint32(r) != uint32(windows.S_OK) {
return nil, fmt.Errorf("directx: D3D12GetDebugInterface failed: HRESULT(%d)", uint32(r)) return nil, fmt.Errorf("directx: D3D12GetDebugInterface failed: %w", handleError(windows.Handle(uint32(r))))
} }
return debug, nil return debug, nil
} }
@ -1067,9 +1067,9 @@ func _D3D12SerializeRootSignature(pRootSignature *_D3D12_ROOT_SIGNATURE_DESC, ve
if uint32(r) != uint32(windows.S_OK) { if uint32(r) != uint32(windows.S_OK) {
if errorBlob != nil { if errorBlob != nil {
defer errorBlob.Release() defer errorBlob.Release()
return nil, fmt.Errorf("directx: D3D12SerializeRootSignature failed: %s: HRESULT(%d)", errorBlob.String(), uint32(r)) return nil, fmt.Errorf("directx: D3D12SerializeRootSignature failed: %s: %w", errorBlob.String(), handleError(windows.Handle(uint32(r))))
} }
return nil, fmt.Errorf("directx: D3D12SerializeRootSignature failed: HRESULT(%d)", uint32(r)) return nil, fmt.Errorf("directx: D3D12SerializeRootSignature failed: %w", handleError(windows.Handle(uint32(r))))
} }
return blob, nil return blob, nil
} }
@ -1078,7 +1078,7 @@ func _D3D12XboxCreateDevice(pAdapter unsafe.Pointer, pParameters *_D3D12XBOX_CRE
var v unsafe.Pointer var v unsafe.Pointer
r, _, _ := procD3D12XboxCreateDevice.Call(uintptr(pAdapter), uintptr(unsafe.Pointer(pParameters)), uintptr(unsafe.Pointer(riid)), uintptr(unsafe.Pointer(&v))) r, _, _ := procD3D12XboxCreateDevice.Call(uintptr(pAdapter), uintptr(unsafe.Pointer(pParameters)), uintptr(unsafe.Pointer(riid)), uintptr(unsafe.Pointer(&v)))
if uint32(r) != uint32(windows.S_OK) { if uint32(r) != uint32(windows.S_OK) {
return nil, fmt.Errorf("directx: D3D12XboxCreateDevice failed: HRESULT(%d)", uint32(r)) return nil, fmt.Errorf("directx: D3D12XboxCreateDevice failed: %w", handleError(windows.Handle(uint32(r))))
} }
return v, nil return v, nil
} }
@ -1108,9 +1108,9 @@ func _D3DCompile(srcData []byte, sourceName string, pDefines []_D3D_SHADER_MACRO
if uint32(r) != uint32(windows.S_OK) { if uint32(r) != uint32(windows.S_OK) {
if errorMsgs != nil { if errorMsgs != nil {
defer errorMsgs.Release() defer errorMsgs.Release()
return nil, fmt.Errorf("directx: D3DCompile failed: %s: HRESULT(%d)", errorMsgs.String(), uint32(r)) return nil, fmt.Errorf("directx: D3DCompile failed: %s: %w", errorMsgs.String(), handleError(windows.Handle(uint32(r))))
} }
return nil, fmt.Errorf("directx: D3DCompile failed: HRESULT(%d)", uint32(r)) return nil, fmt.Errorf("directx: D3DCompile failed: %w", handleError(windows.Handle(uint32(r))))
} }
return code, nil return code, nil
} }
@ -1119,7 +1119,7 @@ func _CreateDXGIFactory2(flags uint32) (*_IDXGIFactory4, error) {
var factory *_IDXGIFactory4 var factory *_IDXGIFactory4
r, _, _ := procCreateDXGIFactory2.Call(uintptr(flags), uintptr(unsafe.Pointer(&_IID_IDXGIFactory4)), uintptr(unsafe.Pointer(&factory))) r, _, _ := procCreateDXGIFactory2.Call(uintptr(flags), uintptr(unsafe.Pointer(&_IID_IDXGIFactory4)), uintptr(unsafe.Pointer(&factory)))
if uint32(r) != uint32(windows.S_OK) { if uint32(r) != uint32(windows.S_OK) {
return nil, fmt.Errorf("directx: CreateDXGIFactory2 failed: HRESULT(%d)", uint32(r)) return nil, fmt.Errorf("directx: CreateDXGIFactory2 failed: %w", handleError(windows.Handle(uint32(r))))
} }
return factory, nil return factory, nil
} }
@ -1262,7 +1262,7 @@ func (i *_ID3D12CommandAllocator) Release() uint32 {
func (i *_ID3D12CommandAllocator) Reset() error { func (i *_ID3D12CommandAllocator) Reset() error {
r, _, _ := syscall.Syscall(i.vtbl.Reset, 1, uintptr(unsafe.Pointer(i)), 0, 0) r, _, _ := syscall.Syscall(i.vtbl.Reset, 1, uintptr(unsafe.Pointer(i)), 0, 0)
if uint32(r) != uint32(windows.S_OK) { if uint32(r) != uint32(windows.S_OK) {
return fmt.Errorf("directx: ID3D12CommandAllocator::Reset failed: HRESULT(%d)", uint32(r)) return fmt.Errorf("directx: ID3D12CommandAllocator::Reset failed: %w", handleError(windows.Handle(uint32(r))))
} }
return nil return nil
} }
@ -1321,7 +1321,7 @@ func (i *_ID3D12CommandQueue) PresentX(planeCount uint32, pPlaneParameters *_D3D
runtime.KeepAlive(pPlaneParameters) runtime.KeepAlive(pPlaneParameters)
runtime.KeepAlive(pPresentParameters) runtime.KeepAlive(pPresentParameters)
if uint32(r) != uint32(windows.S_OK) { if uint32(r) != uint32(windows.S_OK) {
return fmt.Errorf("directx: ID3D12CommandQueue::PresentX failed: HRESULT(%d)", uint32(r)) return fmt.Errorf("directx: ID3D12CommandQueue::PresentX failed: %w", handleError(windows.Handle(uint32(r))))
} }
return nil return nil
} }
@ -1337,7 +1337,7 @@ func (i *_ID3D12CommandQueue) Signal(signal *_ID3D12Fence, value uint64) error {
} }
runtime.KeepAlive(signal) runtime.KeepAlive(signal)
if uint32(r) != uint32(windows.S_OK) { if uint32(r) != uint32(windows.S_OK) {
return fmt.Errorf("directx: ID3D12CommandQueue::Signal failed: HRESULT(%d)", uint32(r)) return fmt.Errorf("directx: ID3D12CommandQueue::Signal failed: %w", handleError(windows.Handle(uint32(r))))
} }
return nil return nil
} }
@ -1408,7 +1408,7 @@ type _ID3D12DebugCommandList_Vtbl struct {
func (i *_ID3D12DebugCommandList) SetFeatureMask(mask _D3D12_DEBUG_FEATURE) error { func (i *_ID3D12DebugCommandList) SetFeatureMask(mask _D3D12_DEBUG_FEATURE) error {
r, _, _ := syscall.Syscall(i.vtbl.SetFeatureMask, 2, uintptr(unsafe.Pointer(i)), uintptr(mask), 0) r, _, _ := syscall.Syscall(i.vtbl.SetFeatureMask, 2, uintptr(unsafe.Pointer(i)), uintptr(mask), 0)
if uint32(r) != uint32(windows.S_OK) { if uint32(r) != uint32(windows.S_OK) {
return fmt.Errorf("directx: ID3D12DebugCommandList::SetFeatureMask failed: HRESULT(%d)", uint32(r)) return fmt.Errorf("directx: ID3D12DebugCommandList::SetFeatureMask failed: %w", handleError(windows.Handle(uint32(r))))
} }
return nil return nil
} }
@ -1587,7 +1587,7 @@ func (i *_ID3D12Device) CreateCommandAllocator(typ _D3D12_COMMAND_LIST_TYPE) (*_
uintptr(typ), uintptr(unsafe.Pointer(&_IID_ID3D12CommandAllocator)), uintptr(unsafe.Pointer(&commandAllocator)), uintptr(typ), uintptr(unsafe.Pointer(&_IID_ID3D12CommandAllocator)), uintptr(unsafe.Pointer(&commandAllocator)),
0, 0) 0, 0)
if uint32(r) != uint32(windows.S_OK) { if uint32(r) != uint32(windows.S_OK) {
return nil, fmt.Errorf("directx: ID3D12Device::CreateCommandAllocator failed: HRESULT(%d)", uint32(r)) return nil, fmt.Errorf("directx: ID3D12Device::CreateCommandAllocator failed: %w", handleError(windows.Handle(uint32(r))))
} }
return commandAllocator, nil return commandAllocator, nil
} }
@ -1619,7 +1619,7 @@ func (i *_ID3D12Device) CreateCommandList(nodeMask uint32, typ _D3D12_COMMAND_LI
runtime.KeepAlive(pCommandAllocator) runtime.KeepAlive(pCommandAllocator)
runtime.KeepAlive(pInitialState) runtime.KeepAlive(pInitialState)
if uint32(r) != uint32(windows.S_OK) { if uint32(r) != uint32(windows.S_OK) {
return nil, fmt.Errorf("directx: ID3D12Device::CreateCommandList failed: HRESULT(%d)", uint32(r)) return nil, fmt.Errorf("directx: ID3D12Device::CreateCommandList failed: %w", handleError(windows.Handle(uint32(r))))
} }
return commandList, nil return commandList, nil
} }
@ -1634,7 +1634,7 @@ func (i *_ID3D12Device) CreateCommittedResource(pHeapProperties *_D3D12_HEAP_PRO
runtime.KeepAlive(pDesc) runtime.KeepAlive(pDesc)
runtime.KeepAlive(pOptimizedClearValue) runtime.KeepAlive(pOptimizedClearValue)
if uint32(r) != uint32(windows.S_OK) { if uint32(r) != uint32(windows.S_OK) {
return nil, fmt.Errorf("directx: ID3D12Device::CreateCommittedResource failed: HRESULT(%d)", uint32(r)) return nil, fmt.Errorf("directx: ID3D12Device::CreateCommittedResource failed: %w", handleError(windows.Handle(uint32(r))))
} }
return resource, nil return resource, nil
} }
@ -1646,7 +1646,7 @@ func (i *_ID3D12Device) CreateCommandQueue(desc *_D3D12_COMMAND_QUEUE_DESC) (*_I
0, 0) 0, 0)
runtime.KeepAlive(desc) runtime.KeepAlive(desc)
if uint32(r) != uint32(windows.S_OK) { if uint32(r) != uint32(windows.S_OK) {
return nil, fmt.Errorf("directx: ID3D12Device::CreateCommandQueue failed: HRESULT(%d)", uint32(r)) return nil, fmt.Errorf("directx: ID3D12Device::CreateCommandQueue failed: %w", handleError(windows.Handle(uint32(r))))
} }
return commandQueue, nil return commandQueue, nil
} }
@ -1664,7 +1664,7 @@ func (i *_ID3D12Device) CreateDescriptorHeap(desc *_D3D12_DESCRIPTOR_HEAP_DESC)
0, 0) 0, 0)
runtime.KeepAlive(desc) runtime.KeepAlive(desc)
if uint32(r) != uint32(windows.S_OK) { if uint32(r) != uint32(windows.S_OK) {
return nil, fmt.Errorf("directx: ID3D12Device::CreateDescriptorHeap failed: HRESULT(%d)", uint32(r)) return nil, fmt.Errorf("directx: ID3D12Device::CreateDescriptorHeap failed: %w", handleError(windows.Handle(uint32(r))))
} }
return descriptorHeap, nil return descriptorHeap, nil
} }
@ -1693,7 +1693,7 @@ func (i *_ID3D12Device) CreateFence(initialValue uint64, flags _D3D12_FENCE_FLAG
uintptr(unsafe.Pointer(&_IID_ID3D12Fence)), uintptr(unsafe.Pointer(&fence))) uintptr(unsafe.Pointer(&_IID_ID3D12Fence)), uintptr(unsafe.Pointer(&fence)))
} }
if uint32(r) != uint32(windows.S_OK) { if uint32(r) != uint32(windows.S_OK) {
return nil, fmt.Errorf("directx: ID3D12Device::CreateFence failed: HRESULT(%d)", uint32(r)) return nil, fmt.Errorf("directx: ID3D12Device::CreateFence failed: %w", handleError(windows.Handle(uint32(r))))
} }
return fence, nil return fence, nil
} }
@ -1705,7 +1705,7 @@ func (i *_ID3D12Device) CreateGraphicsPipelineState(pDesc *_D3D12_GRAPHICS_PIPEL
0, 0) 0, 0)
runtime.KeepAlive(pDesc) runtime.KeepAlive(pDesc)
if uint32(r) != uint32(windows.S_OK) { if uint32(r) != uint32(windows.S_OK) {
return nil, fmt.Errorf("directx: ID3D12Device::CreateGraphicsPipelineState failed: HRESULT(%d)", uint32(r)) return nil, fmt.Errorf("directx: ID3D12Device::CreateGraphicsPipelineState failed: %w", handleError(windows.Handle(uint32(r))))
} }
return pipelineState, nil return pipelineState, nil
} }
@ -1724,7 +1724,7 @@ func (i *_ID3D12Device) CreateRootSignature(nodeMask uint32, pBlobWithRootSignat
uintptr(nodeMask), pBlobWithRootSignature, blobLengthInBytes, uintptr(nodeMask), pBlobWithRootSignature, blobLengthInBytes,
uintptr(unsafe.Pointer(&_IID_ID3D12RootSignature)), uintptr(unsafe.Pointer(&signature))) uintptr(unsafe.Pointer(&_IID_ID3D12RootSignature)), uintptr(unsafe.Pointer(&signature)))
if uint32(r) != uint32(windows.S_OK) { if uint32(r) != uint32(windows.S_OK) {
return nil, fmt.Errorf("directx: ID3D12Device::CreateRootSignature failed: HRESULT(%d)", uint32(r)) return nil, fmt.Errorf("directx: ID3D12Device::CreateRootSignature failed: %w", handleError(windows.Handle(uint32(r))))
} }
return signature, nil return signature, nil
} }
@ -1769,7 +1769,7 @@ func (i *_ID3D12Device) GetDescriptorHandleIncrementSize(descriptorHeapType _D3D
func (i *_ID3D12Device) GetDeviceRemovedReason() error { func (i *_ID3D12Device) GetDeviceRemovedReason() error {
r, _, _ := syscall.Syscall(i.vtbl.GetDeviceRemovedReason, 1, uintptr(unsafe.Pointer(i)), 0, 0) r, _, _ := syscall.Syscall(i.vtbl.GetDeviceRemovedReason, 1, uintptr(unsafe.Pointer(i)), 0, 0)
if uint32(r) != uint32(windows.S_OK) { if uint32(r) != uint32(windows.S_OK) {
return fmt.Errorf("directx: ID3D12Device::GetDeviceRemovedReason failed: HRESULT(%d)", uint32(r)) return fmt.Errorf("directx: ID3D12Device::GetDeviceRemovedReason failed: %w", handleError(windows.Handle(uint32(r))))
} }
return nil return nil
} }
@ -1778,7 +1778,7 @@ func (i *_ID3D12Device) ScheduleFrameEventX(typ _D3D12XBOX_FRAME_EVENT_TYPE, int
r, _, _ := syscall.Syscall6(i.vtbl.ScheduleFrameEventX, 5, uintptr(unsafe.Pointer(i)), uintptr(typ), uintptr(intervalOffsetInMicroseconds), uintptr(unsafe.Pointer(pAncillarySignalList)), uintptr(flags), 0) r, _, _ := syscall.Syscall6(i.vtbl.ScheduleFrameEventX, 5, uintptr(unsafe.Pointer(i)), uintptr(typ), uintptr(intervalOffsetInMicroseconds), uintptr(unsafe.Pointer(pAncillarySignalList)), uintptr(flags), 0)
runtime.KeepAlive(pAncillarySignalList) runtime.KeepAlive(pAncillarySignalList)
if uint32(r) != uint32(windows.S_OK) { if uint32(r) != uint32(windows.S_OK) {
return fmt.Errorf("directx: ID3D12Device::ScheduleFrameEventX failed: HRESULT(%d)", uint32(r)) return fmt.Errorf("directx: ID3D12Device::ScheduleFrameEventX failed: %w", handleError(windows.Handle(uint32(r))))
} }
return nil return nil
} }
@ -1788,7 +1788,7 @@ func (i *_ID3D12Device) SetFrameIntervalX(pOutputSyncTarget *_IDXGIOutput, lengt
runtime.KeepAlive(pOutputSyncTarget) runtime.KeepAlive(pOutputSyncTarget)
// S_FALSE means the call was successful but the new frame interval is not yet in effect. // S_FALSE means the call was successful but the new frame interval is not yet in effect.
if uint32(r) != uint32(windows.S_OK) && uint32(r) != uint32(windows.S_FALSE) { if uint32(r) != uint32(windows.S_OK) && uint32(r) != uint32(windows.S_FALSE) {
return fmt.Errorf("directx: ID3D12Device::SetFrameIntervalX failed: HRESULT(%d)", uint32(r)) return fmt.Errorf("directx: ID3D12Device::SetFrameIntervalX failed: %w", handleError(windows.Handle(uint32(r))))
} }
return nil return nil
} }
@ -1798,7 +1798,7 @@ func (i *_ID3D12Device) QueryInterface(riid *windows.GUID) (unsafe.Pointer, erro
r, _, _ := syscall.Syscall(i.vtbl.QueryInterface, 3, uintptr(unsafe.Pointer(i)), uintptr(unsafe.Pointer(riid)), uintptr(unsafe.Pointer(&v))) r, _, _ := syscall.Syscall(i.vtbl.QueryInterface, 3, uintptr(unsafe.Pointer(i)), uintptr(unsafe.Pointer(riid)), uintptr(unsafe.Pointer(&v)))
runtime.KeepAlive(riid) runtime.KeepAlive(riid)
if uint32(r) != uint32(windows.S_OK) { if uint32(r) != uint32(windows.S_OK) {
return nil, fmt.Errorf("directx: ID3D12Device::QueryInterface failed: HRESULT(%d)", uint32(r)) return nil, fmt.Errorf("directx: ID3D12Device::QueryInterface failed: %w", handleError(windows.Handle(uint32(r))))
} }
return v, nil return v, nil
} }
@ -1808,7 +1808,7 @@ func (i *_ID3D12Device) WaitFrameEventX(typ _D3D12XBOX_FRAME_EVENT_TYPE, timeOut
runtime.KeepAlive(pAncillaryWaitList) runtime.KeepAlive(pAncillaryWaitList)
runtime.KeepAlive(pToken) runtime.KeepAlive(pToken)
if uint32(r) != uint32(windows.S_OK) { if uint32(r) != uint32(windows.S_OK) {
return fmt.Errorf("directx: ID3D12Device::WaitFrameEventX failed: HRESULT(%d)", uint32(r)) return fmt.Errorf("directx: ID3D12Device::WaitFrameEventX failed: %w", handleError(windows.Handle(uint32(r))))
} }
return nil return nil
} }
@ -1856,7 +1856,7 @@ func (i *_ID3D12Fence) SetEventOnCompletion(value uint64, hEvent windows.Handle)
uintptr(value), uintptr(value>>32), uintptr(hEvent), 0, 0) uintptr(value), uintptr(value>>32), uintptr(hEvent), 0, 0)
} }
if uint32(r) != uint32(windows.S_OK) { if uint32(r) != uint32(windows.S_OK) {
return fmt.Errorf("directx: ID3D12Fence::SetEventOnCompletion failed: HRESULT(%d)", uint32(r)) return fmt.Errorf("directx: ID3D12Fence::SetEventOnCompletion failed: %w", handleError(windows.Handle(uint32(r))))
} }
return nil return nil
} }
@ -1969,7 +1969,7 @@ func (i *_ID3D12GraphicsCommandList) Close() error {
r, _, _ = syscall.Syscall(i.vtbl.Close, 1, uintptr(unsafe.Pointer(i)), 0, 0) r, _, _ = syscall.Syscall(i.vtbl.Close, 1, uintptr(unsafe.Pointer(i)), 0, 0)
} }
if uint32(r) != uint32(windows.S_OK) { if uint32(r) != uint32(windows.S_OK) {
return fmt.Errorf("directx: ID3D12GraphicsCommandList::Close failed: HRESULT(%d)", uint32(r)) return fmt.Errorf("directx: ID3D12GraphicsCommandList::Close failed: %w", handleError(windows.Handle(uint32(r))))
} }
return nil return nil
} }
@ -2089,7 +2089,7 @@ func (i *_ID3D12GraphicsCommandList) Reset(pAllocator *_ID3D12CommandAllocator,
runtime.KeepAlive(pAllocator) runtime.KeepAlive(pAllocator)
runtime.KeepAlive(pInitialState) runtime.KeepAlive(pInitialState)
if uint32(r) != uint32(windows.S_OK) { if uint32(r) != uint32(windows.S_OK) {
return fmt.Errorf("directx: ID3D12GraphicsCommandList::Reset failed: HRESULT(%d)", uint32(r)) return fmt.Errorf("directx: ID3D12GraphicsCommandList::Reset failed: %w", handleError(windows.Handle(uint32(r))))
} }
return nil return nil
} }
@ -2249,7 +2249,7 @@ func (i *_ID3D12Resource) Map(subresource uint32, pReadRange *_D3D12_RANGE) (uin
0, 0) 0, 0)
runtime.KeepAlive(pReadRange) runtime.KeepAlive(pReadRange)
if uint32(r) != uint32(windows.S_OK) { if uint32(r) != uint32(windows.S_OK) {
return 0, fmt.Errorf("directx: ID3D12Resource::Map failed: HRESULT(%d)", uint32(r)) return 0, fmt.Errorf("directx: ID3D12Resource::Map failed: %w", handleError(windows.Handle(uint32(r))))
} }
return data, nil return data, nil
} }
@ -2325,7 +2325,7 @@ func (i *_IDXGIAdapter) EnumOutputs(output uint32) (*_IDXGIOutput, error) {
var pOutput *_IDXGIOutput var pOutput *_IDXGIOutput
r, _, _ := syscall.Syscall(i.vtbl.EnumOutputs, 3, uintptr(unsafe.Pointer(i)), uintptr(output), uintptr(unsafe.Pointer(&pOutput))) r, _, _ := syscall.Syscall(i.vtbl.EnumOutputs, 3, uintptr(unsafe.Pointer(i)), uintptr(output), uintptr(unsafe.Pointer(&pOutput)))
if uint32(r) != uint32(windows.S_OK) { if uint32(r) != uint32(windows.S_OK) {
return nil, fmt.Errorf("directx: IDXGIAdapter::EnumOutputs failed: HRESULT(%d)", uint32(r)) return nil, fmt.Errorf("directx: IDXGIAdapter::EnumOutputs failed: %w", handleError(windows.Handle(uint32(r))))
} }
return pOutput, nil return pOutput, nil
} }
@ -2363,7 +2363,7 @@ func (i *_IDXGIAdapter1) GetDesc1() (*_DXGI_ADAPTER_DESC1, error) {
var desc _DXGI_ADAPTER_DESC1 var desc _DXGI_ADAPTER_DESC1
r, _, _ := syscall.Syscall(i.vtbl.GetDesc1, 2, uintptr(unsafe.Pointer(i)), uintptr(unsafe.Pointer(&desc)), 0) r, _, _ := syscall.Syscall(i.vtbl.GetDesc1, 2, uintptr(unsafe.Pointer(i)), uintptr(unsafe.Pointer(&desc)), 0)
if uint32(r) != uint32(windows.S_OK) { if uint32(r) != uint32(windows.S_OK) {
return nil, fmt.Errorf("directx: IDXGIAdapter1::GetDesc1 failed: HRESULT(%d)", uint32(r)) return nil, fmt.Errorf("directx: IDXGIAdapter1::GetDesc1 failed: %w", handleError(windows.Handle(uint32(r))))
} }
return &desc, nil return &desc, nil
} }
@ -2392,7 +2392,7 @@ func (i *_IDXGIDevice) GetAdapter() (*_IDXGIAdapter, error) {
var adapter *_IDXGIAdapter var adapter *_IDXGIAdapter
r, _, _ := syscall.Syscall(i.vtbl.GetAdapter, 2, uintptr(unsafe.Pointer(i)), uintptr(unsafe.Pointer(&adapter)), 0) r, _, _ := syscall.Syscall(i.vtbl.GetAdapter, 2, uintptr(unsafe.Pointer(i)), uintptr(unsafe.Pointer(&adapter)), 0)
if uint32(r) != uint32(windows.S_OK) { if uint32(r) != uint32(windows.S_OK) {
return nil, fmt.Errorf("directx: IDXGIDevice::GetAdapter failed: HRESULT(%d)", uint32(r)) return nil, fmt.Errorf("directx: IDXGIDevice::GetAdapter failed: %w", handleError(windows.Handle(uint32(r))))
} }
return adapter, nil return adapter, nil
} }
@ -2446,7 +2446,7 @@ func (i *_IDXGIFactory4) CreateSwapChainForComposition(pDevice unsafe.Pointer, p
runtime.KeepAlive(pDesc) runtime.KeepAlive(pDesc)
runtime.KeepAlive(pRestrictToOutput) runtime.KeepAlive(pRestrictToOutput)
if uint32(r) != uint32(windows.S_OK) { if uint32(r) != uint32(windows.S_OK) {
return nil, fmt.Errorf("directx: IDXGIFactory4::CreateSwapChainForComposition failed: HRESULT(%d)", uint32(r)) return nil, fmt.Errorf("directx: IDXGIFactory4::CreateSwapChainForComposition failed: %w", handleError(windows.Handle(uint32(r))))
} }
return swapChain, nil return swapChain, nil
} }
@ -2461,7 +2461,7 @@ func (i *_IDXGIFactory4) CreateSwapChainForHwnd(pDevice unsafe.Pointer, hWnd win
runtime.KeepAlive(pFullscreenDesc) runtime.KeepAlive(pFullscreenDesc)
runtime.KeepAlive(pRestrictToOutput) runtime.KeepAlive(pRestrictToOutput)
if uint32(r) != uint32(windows.S_OK) { if uint32(r) != uint32(windows.S_OK) {
return nil, fmt.Errorf("directx: IDXGIFactory4::CreateSwapChainForHwnd failed: HRESULT(%d)", uint32(r)) return nil, fmt.Errorf("directx: IDXGIFactory4::CreateSwapChainForHwnd failed: %w", handleError(windows.Handle(uint32(r))))
} }
return swapChain, nil return swapChain, nil
} }
@ -2479,7 +2479,7 @@ func (i *_IDXGIFactory4) EnumWarpAdapter() (*_IDXGIAdapter1, error) {
var ptr *_IDXGIAdapter1 var ptr *_IDXGIAdapter1
r, _, _ := syscall.Syscall(i.vtbl.EnumWarpAdapter, 3, uintptr(unsafe.Pointer(i)), uintptr(unsafe.Pointer(&_IID_IDXGIAdapter1)), uintptr(unsafe.Pointer(&ptr))) r, _, _ := syscall.Syscall(i.vtbl.EnumWarpAdapter, 3, uintptr(unsafe.Pointer(i)), uintptr(unsafe.Pointer(&_IID_IDXGIAdapter1)), uintptr(unsafe.Pointer(&ptr)))
if uint32(r) != uint32(windows.S_OK) { if uint32(r) != uint32(windows.S_OK) {
return nil, fmt.Errorf("directx: IDXGIFactory4::EnumWarpAdapter failed: HRESULT(%d)", uint32(r)) return nil, fmt.Errorf("directx: IDXGIFactory4::EnumWarpAdapter failed: %w", handleError(windows.Handle(uint32(r))))
} }
return ptr, nil return ptr, nil
} }
@ -2487,7 +2487,7 @@ func (i *_IDXGIFactory4) EnumWarpAdapter() (*_IDXGIAdapter1, error) {
func (i *_IDXGIFactory4) MakeWindowAssociation(windowHandle windows.HWND, flags uint32) error { func (i *_IDXGIFactory4) MakeWindowAssociation(windowHandle windows.HWND, flags uint32) error {
r, _, _ := syscall.Syscall(i.vtbl.MakeWindowAssociation, 3, uintptr(unsafe.Pointer(i)), uintptr(windowHandle), uintptr(flags)) r, _, _ := syscall.Syscall(i.vtbl.MakeWindowAssociation, 3, uintptr(unsafe.Pointer(i)), uintptr(windowHandle), uintptr(flags))
if uint32(r) != uint32(windows.S_OK) { if uint32(r) != uint32(windows.S_OK) {
return fmt.Errorf("directx: IDXGIFactory4::MakeWIndowAssociation failed: HRESULT(%d)", uint32(r)) return fmt.Errorf("directx: IDXGIFactory4::MakeWIndowAssociation failed: %w", handleError(windows.Handle(uint32(r))))
} }
return nil return nil
} }
@ -2497,7 +2497,7 @@ func (i *_IDXGIFactory4) QueryInterface(riid *windows.GUID) (unsafe.Pointer, err
r, _, _ := syscall.Syscall(i.vtbl.QueryInterface, 3, uintptr(unsafe.Pointer(i)), uintptr(unsafe.Pointer(riid)), uintptr(unsafe.Pointer(&v))) r, _, _ := syscall.Syscall(i.vtbl.QueryInterface, 3, uintptr(unsafe.Pointer(i)), uintptr(unsafe.Pointer(riid)), uintptr(unsafe.Pointer(&v)))
runtime.KeepAlive(riid) runtime.KeepAlive(riid)
if uint32(r) != uint32(windows.S_OK) { if uint32(r) != uint32(windows.S_OK) {
return nil, fmt.Errorf("directx: IDXGIFactory4::QueryInterface failed: HRESULT(%d)", uint32(r)) return nil, fmt.Errorf("directx: IDXGIFactory4::QueryInterface failed: %w", handleError(windows.Handle(uint32(r))))
} }
return v, nil return v, nil
} }
@ -2550,7 +2550,7 @@ func (i *_IDXGIFactory5) CheckFeatureSupport(feature _DXGI_FEATURE, pFeatureSupp
0, 0) 0, 0)
runtime.KeepAlive(pFeatureSupportData) runtime.KeepAlive(pFeatureSupportData)
if uint32(r) != uint32(windows.S_OK) { if uint32(r) != uint32(windows.S_OK) {
return fmt.Errorf("directx: IDXGIFactory5::CheckFeatureSupport failed: HRESULT(%d)", uint32(r)) return fmt.Errorf("directx: IDXGIFactory5::CheckFeatureSupport failed: %w", handleError(windows.Handle(uint32(r))))
} }
return nil return nil
} }
@ -2710,7 +2710,7 @@ func (i *_IDXGISwapChain4) GetBuffer(buffer uint32) (*_ID3D12Resource, error) {
uintptr(buffer), uintptr(unsafe.Pointer(&_IID_ID3D12Resource)), uintptr(unsafe.Pointer(&resource)), uintptr(buffer), uintptr(unsafe.Pointer(&_IID_ID3D12Resource)), uintptr(unsafe.Pointer(&resource)),
0, 0) 0, 0)
if uint32(r) != uint32(windows.S_OK) { if uint32(r) != uint32(windows.S_OK) {
return nil, fmt.Errorf("directx: IDXGISwapChain4::GetBuffer failed: HRESULT(%d)", uint32(r)) return nil, fmt.Errorf("directx: IDXGISwapChain4::GetBuffer failed: %w", handleError(windows.Handle(uint32(r))))
} }
return resource, nil return resource, nil
} }
@ -2727,7 +2727,7 @@ func (i *_IDXGISwapChain4) Present(syncInterval uint32, flags uint32) (occluded
if uint32(r) == uint32(windows.DXGI_STATUS_OCCLUDED) { if uint32(r) == uint32(windows.DXGI_STATUS_OCCLUDED) {
return true, nil return true, nil
} }
return false, fmt.Errorf("directx: IDXGISwapChain4::Present failed: HRESULT(%d)", uint32(r)) return false, fmt.Errorf("directx: IDXGISwapChain4::Present failed: %w", handleError(windows.Handle(uint32(r))))
} }
return false, nil return false, nil
} }
@ -2737,7 +2737,7 @@ func (i *_IDXGISwapChain4) ResizeBuffers(bufferCount uint32, width uint32, heigh
uintptr(unsafe.Pointer(i)), uintptr(bufferCount), uintptr(width), uintptr(unsafe.Pointer(i)), uintptr(bufferCount), uintptr(width),
uintptr(height), uintptr(newFormat), uintptr(swapChainFlags)) uintptr(height), uintptr(newFormat), uintptr(swapChainFlags))
if uint32(r) != uint32(windows.S_OK) { if uint32(r) != uint32(windows.S_OK) {
return fmt.Errorf("directx: IDXGISwapChain4::ResizeBuffers failed: HRESULT(%d)", uint32(r)) return fmt.Errorf("directx: IDXGISwapChain4::ResizeBuffers failed: %w", handleError(windows.Handle(uint32(r))))
} }
return nil return nil
} }

View File

@ -90,7 +90,7 @@ func D3D12DLLName() string {
func init() { func init() {
if r := C.XGameRuntimeInitialize(); uint32(r) != uint32(windows.S_OK) { if r := C.XGameRuntimeInitialize(); uint32(r) != uint32(windows.S_OK) {
panic(fmt.Sprintf("microsoftgdk: XSystemGetDeviceType failed: HRESULT(%d)", r)) panic(fmt.Sprintf("microsoftgdk: XSystemGetDeviceType failed: HRESULT(%d)", uint32(r)))
} }
if got, want := _GetACP(), uint32(_CP_UTF8); got != want { if got, want := _GetACP(), uint32(_CP_UTF8); got != want {
panic(fmt.Sprintf("microsoftgdk: GetACP(): got %d, want %d", got, want)) panic(fmt.Sprintf("microsoftgdk: GetACP(): got %d, want %d", got, want))