From ed28861309ec207c4ea5dbd8a904da4a61759ea3 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Sat, 20 Apr 2024 07:02:36 +0000 Subject: [PATCH] app: [X11] don't send events after DestroyEvent Before this change, a FrameEvent may be delivered after DestroyEvent, leading to a panic. Destroy the X11 window immediately thus ensuring no events can be delivered after destroy. Signed-off-by: Elias Naur --- app/os_x11.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/app/os_x11.go b/app/os_x11.go index f5ea42a6..63df17a3 100644 --- a/app/os_x11.go +++ b/app/os_x11.go @@ -389,6 +389,7 @@ func (w *x11Window) ProcessEvent(e event.Event) { func (w *x11Window) shutdown(err error) { w.ProcessEvent(X11ViewEvent{}) w.ProcessEvent(DestroyEvent{Err: err}) + w.destroy() } func (w *x11Window) Event() event.Event { @@ -398,9 +399,6 @@ func (w *x11Window) Event() event.Event { w.dispatch() continue } - if _, destroy := evt.(DestroyEvent); destroy { - w.destroy() - } return evt } } @@ -464,7 +462,12 @@ func (w *x11Window) dispatch() { // Check for pending draw events before checking animation or blocking. // This fixes an issue on Xephyr where on startup XPending() > 0 but // poll will still block. This also prevents no-op calls to poll. - if syn = w.handler.handleEvents(); !syn { + syn = w.handler.handleEvents() + if w.x == nil { + // handleEvents received a close request and destroyed the window. + return + } + if !syn { anim = w.animating if !anim { // Clear poll events.