internal/graphicsdriver/directx: bug fix: ignore DXGI_STATUS_OCCLUDED

When a screen is locked, an Ebitengine application crashed as the
swap chain's Present returned DXGI_STATUS_OCCLUDED.

Let's ignore the error and continue to run the applications. In the
ideal world, an application should stop running during the screen lock,
so let's revisit this later.

This fix also fixes the issue that a Win32API GetCursorPos returned
an error ERROR_ACCESS_DENIED when the screen was locked.

Closes #2179
This commit is contained in:
Hajime Hoshi 2022-07-04 12:55:34 +09:00
parent fc0a5d42b6
commit 29b41fd07f
2 changed files with 6 additions and 1 deletions

View File

@ -2072,6 +2072,10 @@ func (i *iDXGISwapChain4) GetCurrentBackBufferIndex() uint32 {
func (i *iDXGISwapChain4) Present(syncInterval uint32, flags uint32) error {
r, _, _ := syscall.Syscall(i.vtbl.Present, 3, uintptr(unsafe.Pointer(i)), uintptr(syncInterval), uintptr(flags))
if windows.Handle(r) != windows.S_OK {
// During a screen lock, Present fails (#2179).
if windows.Handle(r) == windows.DXGI_STATUS_OCCLUDED {
return nil
}
return fmt.Errorf("directx: IDXGISwapChain4::Present failed: %w", windows.Errno(r))
}
return nil

View File

@ -18,6 +18,7 @@
package ui
import (
"errors"
"fmt"
"runtime"
"unsafe"
@ -169,7 +170,7 @@ func (u *userInterfaceImpl) adjustWindowPosition(x, y int, monitor *glfw.Monitor
func initialMonitorByOS() (*glfw.Monitor, error) {
px, py, err := getCursorPos()
if err != nil {
if err != nil && !errors.Is(err, windows.ERROR_ACCESS_DENIED) {
return nil, err
}
x, y := int(px), int(py)