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 <christopher.waldon.dev@gmail.com>
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2024-07-02 15:06:52 +02:00
parent 4a1b4c2642
commit 86349775b7
+6
View File
@@ -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{}{}