Skip to content

Removed tracking area for tray to prevent mouse leave race condition crash - #11272

Merged
zcbenz merged 3 commits into
electron:masterfrom
syntropy-ai:1-7-x
Jan 10, 2018
Merged

zcbenz merged 3 commits into
electron:masterfrom
syntropy-ai:1-7-x

Conversation

@matt-way

Copy link
Copy Markdown
Contributor

When the tray icon is destroyed, sometimes a mouseExited event is triggered late, causing a crash. This is fixed by explicitly removing the tracking area when removing the tray icon.

@welcome

welcome Bot commented Nov 28, 2017

Copy link
Copy Markdown

💖 Thanks for opening this pull request! 💖

Here is a list of things that will help get it across the finish line:

  • Follow the JavaScript, C++, and Python coding style.
  • Run npm run lint locally to catch formatting errors earlier.
  • Document any user-facing changes you've made following the documentation styleguide.
  • Include tests when adding/changing behavior.
  • Include screenshots and animated GIFs whenever possible.
    We get a lot of pull requests on this repo, so please be patient and we will get back to you as soon as we can.

@ckerr ckerr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The trackingArea_ field should be a managed pointer, I think.

Examples of base::scoped_nsobject<NSStatusItem> use is upstream in reload_button.h, .mm

Comment thread atom/browser/ui/tray_icon_cocoa.mm Outdated
base::scoped_nsobject<NSImage> alternateImage_;
base::scoped_nsobject<NSString> title_;
base::scoped_nsobject<NSStatusItem> statusItem_;
NSTrackingArea *trackingArea_;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a managed pointer:

base::scoped_nsobject<NSTrackingArea> trackingArea_;

Comment thread atom/browser/ui/tray_icon_cocoa.mm Outdated

- (void)removeItem {
// Turn off tracking events to prevent crash
[self removeTrackingArea:trackingArea_];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to

  1. Release the trackingArea_ pointer
  2. Safeguard against multiple calls
if (trackingArea_) {
  [self removeTrackingArea:trackingArea_];
  trackingArea_.reset();
}

Comment thread atom/browser/ui/tray_icon_cocoa.mm Outdated

// Add NSTrackingArea for listening to mouseEnter and mouseExit events
auto trackingArea = [[[NSTrackingArea alloc]
trackingArea_ = [[[NSTrackingArea alloc]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be alloced into the managed pointer:

trackingArea_.reset([[NSTrackingArea alloc] args...);
[self addTrackingArea:trackingArea_];

@matt-way

matt-way commented Dec 3, 2017

Copy link
Copy Markdown
Contributor Author

Have made the changes to the mem management

@ckerr

ckerr commented Dec 3, 2017

Copy link
Copy Markdown
Member

These CI failures seem unrelated to the pull request. I've pinged @jkleinsc in the #ci channel for a second opinion.

@felixrieseberg felixrieseberg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logic seems sound to me. I have never seen the crash, but this is a cheap operation that makes sense to me.

@MarshallOfSound MarshallOfSound left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't go straight to 1.7.x, it should go to master and then backported manually after the initial merge

@ckerr

ckerr commented Dec 3, 2017

Copy link
Copy Markdown
Member

+1 on putting this in master

@jkleinsc
jkleinsc changed the base branch from 1-7-x to master December 4, 2017 14:56
@jkleinsc
jkleinsc changed the base branch from master to 1-7-x December 4, 2017 14:56
@jkleinsc

jkleinsc commented Dec 4, 2017

Copy link
Copy Markdown
Member

@matt-way can you do this change in master instead of 1-7-x? It can then be manually backported to 1-7-x

@zcbenz
zcbenz changed the base branch from 1-7-x to master January 10, 2018 01:25
@zcbenz
zcbenz requested a review from a team January 10, 2018 01:25
@zcbenz

zcbenz commented Jan 10, 2018

Copy link
Copy Markdown
Contributor

The failing test is not related to this PR, I'm merging this anyway.

@zcbenz
zcbenz merged commit 143816b into electron:master Jan 10, 2018
@welcome

welcome Bot commented Jan 10, 2018

Copy link
Copy Markdown

Congrats on merging your first pull request! 🎉🎉🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants