From 4d5711291ed396ed6843439fa1fe5c7e1f1e1a8c Mon Sep 17 00:00:00 2001 From: Kenneth Russell Date: Fri, 15 Oct 2021 16:27:05 -0700 Subject: [PATCH] Suppress ObjC exceptions in OSXWindow::messageLoop. Crashes have been seen inside the Cocoa-internal NS_setFlushesWithDisplayLink function. Web searches indicate this is a regression in macOS 11. See whether catching and ignoring these exceptions improves stability. Bug: angleproject:6570 Change-Id: Id0be68077163bf4e9f98189461eea016a35edd73 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3227697 Commit-Queue: Kenneth Russell Reviewed-by: Tim Van Patten --- util/osx/OSXWindow.mm | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/util/osx/OSXWindow.mm b/util/osx/OSXWindow.mm index c3c7c8dda..27d8e6cad 100644 --- a/util/osx/OSXWindow.mm +++ b/util/osx/OSXWindow.mm @@ -712,20 +712,31 @@ void OSXWindow::messageLoop() { while (true) { - NSEvent *event = [NSApp nextEventMatchingMask:NSAnyEventMask - untilDate:[NSDate distantPast] - inMode:NSDefaultRunLoopMode - dequeue:YES]; - if (event == nil) + // TODO(http://anglebug.com/6570): @try/@catch is a workaround for + // exceptions being thrown from Cocoa-internal function + // NS_setFlushesWithDisplayLink starting in macOS 11. + @try { - break; - } + NSEvent *event = [NSApp nextEventMatchingMask:NSAnyEventMask + untilDate:[NSDate distantPast] + inMode:NSDefaultRunLoopMode + dequeue:YES]; + if (event == nil) + { + break; + } - if ([event type] == NSAppKitDefined) - { - continue; + if ([event type] == NSAppKitDefined) + { + continue; + } + [NSApp sendEvent:event]; + } + @catch (NSException *localException) + { + NSLog(@"*** OSXWindow discarding exception: <%@> %@", [localException name], + [localException reason]); } - [NSApp sendEvent:event]; } } }