diff --git a/internal/glfwwin/monitor_windows.go b/internal/glfwwin/monitor_windows.go index 630f5439e..be57afbf7 100644 --- a/internal/glfwwin/monitor_windows.go +++ b/internal/glfwwin/monitor_windows.go @@ -93,6 +93,7 @@ func inputMonitor(monitor *Monitor, action PeripheralEvent, placement int) error for i, m := range _glfw.monitors { if m == monitor { copy(_glfw.monitors[i:], _glfw.monitors[i+1:]) + _glfw.monitors[len(_glfw.monitors)-1] = nil _glfw.monitors = _glfw.monitors[:len(_glfw.monitors)-1] break } diff --git a/internal/glfwwin/window_windows.go b/internal/glfwwin/window_windows.go index 8cc1869c1..3ddd48baa 100644 --- a/internal/glfwwin/window_windows.go +++ b/internal/glfwwin/window_windows.go @@ -139,6 +139,7 @@ func CreateWindow(width, height int, title string, monitor *Monitor, share *Wind window.Destroy() } }() + _glfw.windows = append(_glfw.windows, window) // Open the actual window and create its context if err := window.platformCreateWindow(&wndconfig, &ctxconfig, &fbconfig); err != nil { @@ -312,7 +313,7 @@ func (w *Window) Destroy() error { } // Clear all callbacks to avoid exposing a half torn-down w object - //memset(&w.callbacks, 0, sizeof(w.callbacks)) + // TODO: Clear w.callbacks // The w's context must not be current on another thread when the // w is destroyed @@ -326,6 +327,15 @@ func (w *Window) Destroy() error { } } + for i, window := range _glfw.windows { + if window == w { + copy(_glfw.windows[i:], _glfw.windows[i+1:]) + _glfw.windows[len(_glfw.windows)-1] = nil + _glfw.windows = _glfw.windows[:len(_glfw.windows)-1] + break + } + } + w.platformDestroyWindow() return nil }