From 06c1b5903ba59ae38607f0f7c348dc903297a819 Mon Sep 17 00:00:00 2001 From: mitchmindtree Date: Sun, 5 Feb 2017 19:01:27 +1100 Subject: [PATCH] Fix bug where an NSEvent is produced when a user opens spotlight while the NSApplication is in focus. This NSEvent produces an undocumented NSEventType value `21` that has no associated variant within the cocoa-rs crate's `NSEventType` enum, thus causing a segfault when attemptingt to match on the value. This commit adds a check for `21` to avoid the segfault. This fixes #104. --- src/platform/macos/events_loop.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/platform/macos/events_loop.rs b/src/platform/macos/events_loop.rs index 970ab5e2..fd416a0b 100644 --- a/src/platform/macos/events_loop.rs +++ b/src/platform/macos/events_loop.rs @@ -223,6 +223,16 @@ impl EventsLoop { return None; } + // FIXME: Despite not being documented anywhere, an `NSEvent` is produced when a user opens + // Spotlight while the NSApplication is in focus. This `NSEvent` produces a `NSEventType` + // with value `21`. This causes a SEGFAULT as soon as we try to match on the `NSEventType` + // enum as there is variant associated with the value. Thus, we return early if this sneaky + // event occurs. If someone does find some documentation on this, please fix this by adding + // an appropriate variant to the `NSEventType` enum in the cocoa-rs crate. + if ns_event.eventType() as u64 == 21 { + return None; + } + let event_type = ns_event.eventType(); let ns_window = ns_event.window(); let window_id = super::window::get_window_id(ns_window);