mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
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:
@@ -387,6 +387,9 @@ func (w *Window) setNextFrame(at time.Time) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *callbacks) SetDriver(d driver) {
|
func (c *callbacks) SetDriver(d driver) {
|
||||||
|
if d == nil {
|
||||||
|
panic("nil driver")
|
||||||
|
}
|
||||||
c.w.driver = d
|
c.w.driver = d
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -635,6 +638,9 @@ func (w *Window) processEvent(e event.Event) bool {
|
|||||||
w.coalesced.frame = &e2
|
w.coalesced.frame = &e2
|
||||||
case DestroyEvent:
|
case DestroyEvent:
|
||||||
w.destroyGPU()
|
w.destroyGPU()
|
||||||
|
w.invMu.Lock()
|
||||||
|
w.mayInvalidate = false
|
||||||
|
w.invMu.Unlock()
|
||||||
w.driver = nil
|
w.driver = nil
|
||||||
if q := w.timer.quit; q != nil {
|
if q := w.timer.quit; q != nil {
|
||||||
q <- struct{}{}
|
q <- struct{}{}
|
||||||
|
|||||||
Reference in New Issue
Block a user