From 11f39582b84703c33d3aae4c1b703698a1bb4ea6 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Fri, 7 Jan 2022 18:16:40 +0100 Subject: [PATCH] app: [macOS] pace display link On macOS the display link that drives redraws runs on a separate thread, and must switch to the main thread to invalidate its view. This change makes sure the display link can never call invalidate faster than we can draw. Signed-off-by: Elias Naur --- app/os_macos.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/app/os_macos.go b/app/os_macos.go index 270db6a6..4c754d62 100644 --- a/app/os_macos.go +++ b/app/os_macos.go @@ -558,10 +558,14 @@ func newOSWindow() (*window, error) { view: view, scale: scale, } + done := make(chan struct{}) + setNeedsDisplay := func() { + C.setNeedsDisplay(w.view) + done <- struct{}{} + } dl, err := NewDisplayLink(func() { - w.runOnMain(func() { - C.setNeedsDisplay(w.view) - }) + w.runOnMain(setNeedsDisplay) + <-done }) w.displayLink = dl if err != nil {