From fd0ddee63c9c9b29cffde8b7f341b1f9e95c973c Mon Sep 17 00:00:00 2001 From: mitchmindtree Date: Sat, 4 Feb 2017 02:55:42 +1100 Subject: [PATCH] Panic if the user attempts to run an event loop on a non-main thread on macOS --- src/platform/macos/events_loop.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/platform/macos/events_loop.rs b/src/platform/macos/events_loop.rs index 99ed1a17..b9fbbba2 100644 --- a/src/platform/macos/events_loop.rs +++ b/src/platform/macos/events_loop.rs @@ -47,6 +47,10 @@ impl EventsLoop { where F: FnMut(Event), { unsafe { + if !msg_send![cocoa::base::class("NSThread"), isMainThread] { + panic!("Events can only be polled from the main thread on macOS"); + } + self.store_callback(callback); } @@ -94,6 +98,10 @@ impl EventsLoop { self.interrupted.store(false, std::sync::atomic::Ordering::Relaxed); unsafe { + if !msg_send![cocoa::base::class("NSThread"), isMainThread] { + panic!("Events can only be polled from the main thread on macOS"); + } + self.store_callback(callback); }