From 86349775b7734bf72fbda72106c3dfd32929e4ef Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Tue, 2 Jul 2024 15:06:52 +0200 Subject: [PATCH] app: ensure Invalidate can be invoked when window is closing This commit ensures that it is safe to invoke Invalidate() from another goroutine while a Gio window may be in the process of closing. It can be difficult to prevent this from happening, as window handles can easily be managed by a type that doesn't know the exact moment of window close (it might be waiting on the window event loop to return, but that hasn't happened yet). Without this change, the nil window driver results in a panic in this situation. Co-authored-by: Chris Waldon Signed-off-by: Elias Naur --- app/window.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/window.go b/app/window.go index bf85099a..79a8c6a8 100644 --- a/app/window.go +++ b/app/window.go @@ -387,6 +387,9 @@ func (w *Window) setNextFrame(at time.Time) { } func (c *callbacks) SetDriver(d driver) { + if d == nil { + panic("nil driver") + } c.w.driver = d } @@ -635,6 +638,9 @@ func (w *Window) processEvent(e event.Event) bool { w.coalesced.frame = &e2 case DestroyEvent: w.destroyGPU() + w.invMu.Lock() + w.mayInvalidate = false + w.invMu.Unlock() w.driver = nil if q := w.timer.quit; q != nil { q <- struct{}{}