diff --git a/internal/glfwwin/wglcontext_windows.go b/internal/glfwwin/wglcontext_windows.go index fdab2b2a7..81de11ba4 100644 --- a/internal/glfwwin/wglcontext_windows.go +++ b/internal/glfwwin/wglcontext_windows.go @@ -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 diff --git a/internal/ui/ui_glfw.go b/internal/ui/ui_glfw.go index bdfebcf23..fd7ac8233 100644 --- a/internal/ui/ui_glfw.go +++ b/internal/ui/ui_glfw.go @@ -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 {