internal/ui: bug fix: ignore ERROR_BUSY when deleting a GL context

Closes #2518
This commit is contained in:
Hajime Hoshi 2023-01-02 15:04:25 +09:00
parent 7018318546
commit 471237b701
2 changed files with 8 additions and 3 deletions

View File

@ -6,10 +6,13 @@
package glfwwin
import (
"errors"
"fmt"
"strings"
"unsafe"
"golang.org/x/sys/windows"
"github.com/hajimehoshi/ebiten/v2/internal/microsoftgdk"
)
@ -321,7 +324,10 @@ func getProcAddressWGL(procname string) uintptr {
func destroyContextWGL(window *Window) error {
if window.context.wgl.handle != 0 {
if err := wglDeleteContext(window.context.wgl.handle); err != nil {
// Ignore ERROR_BUSY. This happens when the thread is different from the context thread (#2518).
// This is a known issue of GLFW (glfw/glfw#2239).
// TODO: Delete the context on an appropriate thread.
if err := wglDeleteContext(window.context.wgl.handle); err != nil && !errors.Is(err, windows.ERROR_BUSY) {
return err
}
window.context.wgl.handle = 0

View File

@ -1004,8 +1004,7 @@ func (u *userInterfaceImpl) update() (float64, float64, error) {
func (u *userInterfaceImpl) loopGame() error {
defer u.mainThread.Call(func() {
// An explicit destorying a window tries to delete a GL context on the main thread on Windows (wglDeleteContext),
// but this causes an error unfortunately.
u.window.Destroy()
glfw.Terminate()
})
for {