Skip to content

Commit

Permalink
internal/graphicsdriver/directx: bug fix: disable fullscreen by Alt+E…
Browse files Browse the repository at this point in the history
…nter

By default, DirectX 12 tries to make the window fullscreen by Alt+Enter.
This caused application crashes. Let's disable this feature.

Closes #2123
  • Loading branch information
hajimehoshi committed Jun 5, 2022
1 parent 51fe48f commit 0256b0c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
11 changes: 11 additions & 0 deletions internal/graphicsdriver/directx/api_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,9 @@ const (
_DXGI_CREATE_FACTORY_DEBUG = 0x01

_DXGI_ERROR_NOT_FOUND = windows.Errno(0x887A0002)

_DXGI_MWA_NO_ALT_ENTER = 0x2
_DXGI_MWA_NO_WINDOW_CHANGES = 0x1
)

var (
Expand Down Expand Up @@ -1953,6 +1956,14 @@ func (i *_IDXGIFactory4) EnumWarpAdapter() (*_IDXGIAdapter1, error) {
return ptr, nil
}

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))
if uint32(r) != uint32(windows.S_OK) {
return fmt.Errorf("directx: IDXGIFactory4::MakeWIndowAssociation failed: HRESULT(%d)", uint32(r))
}
return nil
}

func (i *_IDXGIFactory4) Release() {
syscall.Syscall(i.vtbl.Release, 1, uintptr(unsafe.Pointer(i)), 0, 0)
}
Expand Down
7 changes: 6 additions & 1 deletion internal/graphicsdriver/directx/graphics_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,12 @@ func (g *Graphics) initSwapChain(width, height int) (ferr error) {
}
}()

// TODO: Call factory.MakeWindowAssociation not to support fullscreen transitions?
// MakeWindowAssociation should be called after swap chain creation.
// https://docs.microsoft.com/en-us/windows/win32/api/dxgi/nf-dxgi-idxgifactory-makewindowassociation
if err := g.factory.MakeWindowAssociation(g.window, _DXGI_MWA_NO_WINDOW_CHANGES | _DXGI_MWA_NO_ALT_ENTER); err != nil {
return err
}

// TODO: Get the current buffer index?

if err := g.createRenderTargetViews(); err != nil {
Expand Down

0 comments on commit 0256b0c

Please sign in to comment.