fix: resolve crash on close bug in macos#5162
Merged
Merged
Conversation
…tain notifications after main window is destroyed 8a5014c Fixes bitcoin#26490 by preventing notifications (John Moffett) Pull request description: This is a PR to address bitcoin#26490 The menu bar currently subscribes to window focus change notifications to enable or disable certain menu options in response to the window status. Notifications are automatically unsubscribed (disconnected in Qt parlance) if the sender is deleted -- in this case, the sender is the QTApplication object (`qApp`). However, MacOS 13 sends a window focus change notification *after* the main window has been destroyed but *before* `qApp` has been fully destroyed. Since the menu bar is deleted in the main window's destructor, it no longer exists when it receives these notifications (in two different places via lambda expressions). The solution is to pass the main window (`this`) as context when subscribing to the notifications. In this [overloaded version](https://doc.qt.io/qt-5/qobject.html#connect-1) of `connect`, Qt automatically unsubscribes to notifications if the sender OR context (here the main window object) is destroyed. Since the spurious notifications are sent after the main window object is destroyed, this change prevents them from being sent. Tested on Mac OS 13 and 12 only. ACKs for top commit: hebasto: ACK 8a5014c Tree-SHA512: 3dff0a252fe0e93dd68cf5503135ecf6a72bcf385ba38407d6021ab77cca323f8bbe58aeca90ec124aa2a22ab9d35b706946179ac3b5d171c96a7010de51a090
1fa890d to
512503c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue being fixed or feature implemented
Fixes two crash on close bugs on macOS. I thought there were some GitHub issues that describe them, but I can't find them now.
This should be merged via merge commit to preserve the fact this is a backport
What was done?
zoom_action and minimize_action are both actions inside of window_menu and window_menu is inside of appMenuBar. appMenuBar is deleted on quit, which also deletes all the stuff inside of it, and invalidates the pointers we are holding onto inside of these lambdas. I had a different fix that was from capturing
thisinside of the lambda, and checking if appMenuBar was deleted yet, however bitcoin actually dealt with this fix in bitcoin-core/gui#680This should get back ported if we create another 18.2 / 18.1 version
How Has This Been Tested?
starting and stopping many times
Breaking Changes
None
Checklist:
For repository code-owners and collaborators only