From 638d8219c4923da8259d2481ed9fadbcd512fde2 Mon Sep 17 00:00:00 2001 From: Matt Way Date: Tue, 28 Nov 2017 18:20:38 +1000 Subject: [PATCH 1/3] Removed tracking area when removing icon to prevent mouse exit race condition crash --- atom/browser/ui/tray_icon_cocoa.mm | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/atom/browser/ui/tray_icon_cocoa.mm b/atom/browser/ui/tray_icon_cocoa.mm index 9c5e100a2a0c..85477e6a7044 100644 --- a/atom/browser/ui/tray_icon_cocoa.mm +++ b/atom/browser/ui/tray_icon_cocoa.mm @@ -33,6 +33,7 @@ const CGFloat kVerticalTitleMargin = 2; base::scoped_nsobject title_; base::scoped_nsobject attributedTitle_; base::scoped_nsobject statusItem_; + NSTrackingArea *trackingArea_; } @end // @interface StatusItemView @@ -61,12 +62,12 @@ const CGFloat kVerticalTitleMargin = 2; [self updateDimensions]; // Add NSTrackingArea for listening to mouseEnter, mouseExit, and mouseMove events - auto trackingArea = [[[NSTrackingArea alloc] + trackingArea_ = [[[NSTrackingArea alloc] initWithRect:[self bounds] options:NSTrackingMouseEnteredAndExited | NSTrackingMouseMoved | NSTrackingActiveAlways owner:self userInfo:nil] autorelease]; - [self addTrackingArea:trackingArea]; + [self addTrackingArea:trackingArea_]; } return self; } @@ -78,6 +79,8 @@ const CGFloat kVerticalTitleMargin = 2; } - (void)removeItem { + // Turn off tracking events to prevent crash + [self removeTrackingArea:trackingArea_]; [[NSStatusBar systemStatusBar] removeStatusItem:statusItem_]; statusItem_.reset(); } @@ -399,8 +402,9 @@ TrayIconCocoa::TrayIconCocoa() : menu_model_(nullptr) { TrayIconCocoa::~TrayIconCocoa() { [status_item_view_ removeItem]; - if (menu_model_) + if (menu_model_){ menu_model_->RemoveObserver(this); + } } void TrayIconCocoa::SetImage(const gfx::Image& image) { From 8df4402722aef1408f4e735fd53263ee666d824c Mon Sep 17 00:00:00 2001 From: Matt Way Date: Tue, 28 Nov 2017 18:27:47 +1000 Subject: [PATCH 2/3] removed unnecessary braces --- atom/browser/ui/tray_icon_cocoa.mm | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/atom/browser/ui/tray_icon_cocoa.mm b/atom/browser/ui/tray_icon_cocoa.mm index 85477e6a7044..ab1c00742522 100644 --- a/atom/browser/ui/tray_icon_cocoa.mm +++ b/atom/browser/ui/tray_icon_cocoa.mm @@ -402,9 +402,8 @@ TrayIconCocoa::TrayIconCocoa() : menu_model_(nullptr) { TrayIconCocoa::~TrayIconCocoa() { [status_item_view_ removeItem]; - if (menu_model_){ + if (menu_model_) menu_model_->RemoveObserver(this); - } } void TrayIconCocoa::SetImage(const gfx::Image& image) { From 5504294a6a422b1d788fb0e8d795f144e590ff25 Mon Sep 17 00:00:00 2001 From: Matt Way Date: Wed, 29 Nov 2017 17:10:43 +1000 Subject: [PATCH 3/3] Replaces tracking removal with proper mem management --- atom/browser/ui/tray_icon_cocoa.mm | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/atom/browser/ui/tray_icon_cocoa.mm b/atom/browser/ui/tray_icon_cocoa.mm index ab1c00742522..6c2def356cd1 100644 --- a/atom/browser/ui/tray_icon_cocoa.mm +++ b/atom/browser/ui/tray_icon_cocoa.mm @@ -33,7 +33,7 @@ const CGFloat kVerticalTitleMargin = 2; base::scoped_nsobject title_; base::scoped_nsobject attributedTitle_; base::scoped_nsobject statusItem_; - NSTrackingArea *trackingArea_; + base::scoped_nsobject trackingArea_; } @end // @interface StatusItemView @@ -62,11 +62,11 @@ const CGFloat kVerticalTitleMargin = 2; [self updateDimensions]; // Add NSTrackingArea for listening to mouseEnter, mouseExit, and mouseMove events - trackingArea_ = [[[NSTrackingArea alloc] + trackingArea_.reset([[NSTrackingArea alloc] initWithRect:[self bounds] options:NSTrackingMouseEnteredAndExited | NSTrackingMouseMoved | NSTrackingActiveAlways owner:self - userInfo:nil] autorelease]; + userInfo:nil]); [self addTrackingArea:trackingArea_]; } return self; @@ -80,7 +80,10 @@ const CGFloat kVerticalTitleMargin = 2; - (void)removeItem { // Turn off tracking events to prevent crash - [self removeTrackingArea:trackingArea_]; + if (trackingArea_) { + [self removeTrackingArea:trackingArea_]; + trackingArea_.reset(); + } [[NSStatusBar systemStatusBar] removeStatusItem:statusItem_]; statusItem_.reset(); }