From 2a0a196d1ae4ac592baffa73a4b799103b705620 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Fri, 27 May 2022 11:31:13 +0200 Subject: [PATCH] app: don't deadlock if Window.validateAndProcess fails Fixes: https://todo.sr.ht/~eliasnaur/gio/417 Signed-off-by: Elias Naur --- app/window.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/app/window.go b/app/window.go index 6169fde6..2cd1e7bc 100644 --- a/app/window.go +++ b/app/window.go @@ -178,7 +178,16 @@ func (w *Window) update(frame *op.Ops) { <-w.frameAck } -func (w *Window) validateAndProcess(d driver, size image.Point, sync bool, frame *op.Ops, signal chan<- struct{}) error { +func (w *Window) validateAndProcess(d driver, size image.Point, sync bool, frame *op.Ops, sigChan chan<- struct{}) error { + signal := func() { + if sigChan != nil { + // We're done with frame, let the client continue. + sigChan <- struct{}{} + // Signal at most once. + sigChan = nil + } + } + defer signal() for { if w.gpu == nil && !w.nocontext { var err error @@ -235,10 +244,9 @@ func (w *Window) validateAndProcess(d driver, size image.Point, sync bool, frame } } w.queue.q.Frame(frame) - // We're done with frame, let the client continue. - if signal != nil { - signal <- struct{}{} - } + // Let the client continue as soon as possible, in particular before + // a potentially blocking Present. + signal() var err error if w.gpu != nil { err = w.ctx.Present()