cocoa: Fix abort on touch event types without a subtype macOS 10.6 has some touch NSEvents which do not have a subtype (Begin/EndGesture, Magnify, Rotate, Swipe) and cause an uncaught exception which triggers SIGABRT and the program exits. As it is, none of the macOS 10.6 touch events are detected as a trackpad (including Gesture due to using different subtypes).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
diff --git a/src/video/cocoa/SDL_cocoawindow.m b/src/video/cocoa/SDL_cocoawindow.m
index 37b4c15..af9e3db 100644
--- a/src/video/cocoa/SDL_cocoawindow.m
+++ b/src/video/cocoa/SDL_cocoawindow.m
@@ -1319,7 +1319,18 @@ Cocoa_UpdateClipCursor(SDL_Window * window)
{
/* probably a MacBook trackpad; make this look like a synthesized event.
This is backwards from reality, but better matches user expectations. */
- const BOOL istrackpad = ([theEvent subtype] == NSEventSubtypeMouseEvent);
+ BOOL istrackpad = NO;
+ @try {
+ istrackpad = ([theEvent subtype] == NSEventSubtypeMouseEvent);
+ }
+ @catch (NSException *e) {
+ /* if NSEvent type doesn't have subtype, such as NSEventTypeBeginGesture on
+ * macOS 10.5 to 10.10, then NSInternalInconsistencyException is thrown.
+ * This still prints a message to terminal so catching it's not an ideal solution.
+ *
+ * *** Assertion failure in -[NSEvent subtype]
+ */
+ }
NSSet *touches = [theEvent touchesMatchingPhase:NSTouchPhaseAny inView:nil];
const SDL_TouchID touchID = istrackpad ? SDL_MOUSE_TOUCHID : (SDL_TouchID)(intptr_t)[[touches anyObject] device];
@@ -1370,7 +1381,18 @@ Cocoa_UpdateClipCursor(SDL_Window * window)
/* probably a MacBook trackpad; make this look like a synthesized event.
This is backwards from reality, but better matches user expectations. */
- const BOOL istrackpad = ([theEvent subtype] == NSEventSubtypeMouseEvent);
+ BOOL istrackpad = NO;
+ @try {
+ istrackpad = ([theEvent subtype] == NSEventSubtypeMouseEvent);
+ }
+ @catch (NSException *e) {
+ /* if NSEvent type doesn't have subtype, such as NSEventTypeBeginGesture on
+ * macOS 10.5 to 10.10, then NSInternalInconsistencyException is thrown.
+ * This still prints a message to terminal so catching it's not an ideal solution.
+ *
+ * *** Assertion failure in -[NSEvent subtype]
+ */
+ }
for (NSTouch *touch in touches) {
const SDL_TouchID touchId = istrackpad ? SDL_MOUSE_TOUCHID : (SDL_TouchID)(intptr_t)[touch device];