From 9d778d7bde573e632ffcf6e221f2f5270bdff46a Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Sun, 6 Feb 2022 11:21:00 +0100 Subject: [PATCH] app: ensure derived events are processed A range loop may not see all items in a slice that is appended to during iteration. Convert range loop to popping each event off the queue until it is empty. Fixes: https://todo.sr.ht/~eliasnaur/gio/356 Signed-off-by: Elias Naur --- app/window.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/window.go b/app/window.go index 23101a03..a1727dc1 100644 --- a/app/window.go +++ b/app/window.go @@ -423,10 +423,12 @@ func (c *callbacks) Event(e event.Event) { defer func() { c.busy = false }() - for _, e := range c.waitEvents { + for len(c.waitEvents) > 0 { + e := c.waitEvents[0] + copy(c.waitEvents, c.waitEvents[1:]) + c.waitEvents = c.waitEvents[:len(c.waitEvents)-1] c.w.processEvent(c.d, e) } - c.waitEvents = c.waitEvents[:0] c.w.updateState(c.d) if c.w.closing { c.w.closing = false