From df0e058ea6a90f0a581231477cd3d25cd07680b7 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Wed, 19 May 2021 17:19:00 +0200 Subject: [PATCH] app/internal/wm: [macOS] avoid deadlock in Window.Close Native window callbacks now run in the same context as the event loop. However, a call to Close immediately calls onClose which in turn wants to send events. Break the deadlock by deferring the Close call. Fixes gio#227 Signed-off-by: Elias Naur --- app/internal/wm/os_macos.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/internal/wm/os_macos.go b/app/internal/wm/os_macos.go index c34da229..fa4d023f 100644 --- a/app/internal/wm/os_macos.go +++ b/app/internal/wm/os_macos.go @@ -206,7 +206,13 @@ func (w *window) runOnMain(f func()) { } func (w *window) Close() { - C.gio_close(w.window) + // gio_close immediately calls gio_onClose which sends events + // causing a deadlock because Close is called during an event. + // Break the deadlock by deferring the close, making Close more + // akin to a message like the other platforms. + go runOnMain(func() { + C.gio_close(w.window) + }) } func (w *window) setStage(stage system.Stage) {