diff --git a/internal/driver/glfw/loop.go b/internal/driver/glfw/loop.go index 82d5dc0cb5..c20d6e9af8 100644 --- a/internal/driver/glfw/loop.go +++ b/internal/driver/glfw/loop.go @@ -127,8 +127,7 @@ func (d *gLDriver) runGL() { //case <-eventTick.C: default: d.tryWaitEventsTimeout(0.08333) - newWindows := []fyne.Window{} - reassign := false + windowsToRemove := 0 for _, win := range d.windowList() { w := win.(*window) if w.viewport == nil { @@ -136,7 +135,7 @@ func (d *gLDriver) runGL() { } if w.viewport.ShouldClose() { - reassign = true + windowsToRemove++ w.viewLock.Lock() w.visible = false v := w.viewport @@ -165,13 +164,35 @@ func (d *gLDriver) runGL() { } } - newWindows = append(newWindows, win) - if drawOnMainThread { d.drawSingleFrame() } } - if reassign { + if windowsToRemove > 0 { + oldWindows := d.windowList() + newWindows := make([]fyne.Window, 0, len(oldWindows)-windowsToRemove) + + for _, win := range oldWindows { + w := win.(*window) + if w.viewport == nil { + continue + } + + if w.viewport.ShouldClose() { + w.viewLock.Lock() + w.visible = false + v := w.viewport + w.viewLock.Unlock() + + // remove window from window list + v.Destroy() + w.destroy(d) + continue + } + + newWindows = append(newWindows, win) + } + d.windowLock.Lock() d.windows = newWindows d.windowLock.Unlock()