From 10688915eb2fc5a67a60f0b6080da67dcf2fc134 Mon Sep 17 00:00:00 2001 From: YVT Date: Tue, 17 Apr 2018 07:09:02 +0900 Subject: [PATCH] [macOS] Register the Cocoa main thread at an earlier point (#456) Solves the issues caused by calling `EventsLoopProxy::wakeup()` too early from a worker thread. --- src/platform/macos/events_loop.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/platform/macos/events_loop.rs b/src/platform/macos/events_loop.rs index ea756812..ac51eec1 100644 --- a/src/platform/macos/events_loop.rs +++ b/src/platform/macos/events_loop.rs @@ -179,6 +179,13 @@ impl UserCallback { impl EventsLoop { pub fn new() -> Self { + // Mark this thread as the main thread of the Cocoa event system. + // + // This must be done before any worker threads get a chance to call it + // (e.g., via `EventsLoopProxy::wakeup()`), causing a wrong thread to be + // marked as the main thread. + unsafe { appkit::NSApp(); } + EventsLoop { shared: Arc::new(Shared::new()), modifiers: Modifiers::new(),