Skip to content

Commit 64ffa94

Browse files
furszyfanquake
authored andcommitted
gui: macOS, do not process dock icon actions during shutdown
As the 'QMenuBar' is created without a parent window in MacOS, the app crashes when the user presses the shutdown button and, right after it, triggers any action in the menu bar. This happens because the QMenuBar is manually deleted in the BitcoinGUI destructor but the events attached to it children actions are not disconnected, so QActions events such us the 'QMenu::aboutToShow' could try to access null pointers. Instead of guarding every single QAction pointer inside the QMenu::aboutToShow slot, or manually disconnecting all registered events in the destructor, we can check if a shutdown was requested and discard the event. The 'node' field is a ref whose memory is held by the main application class, so it is safe to use here. Events are disconnected prior destructing the main application object. Furthermore, the 'MacDockIconHandler::dockIconClicked' signal can make the app crash during shutdown for the very same reason. The 'show()' call triggers the 'QApplication::focusWindowChanged' event, which is connected to the 'minimize_action' QAction, which is also part of the app menu bar, which could no longer exist. Github-Pull: gui#751 Rebased-From: e14cc8f
1 parent e270f3f commit 64ffa94

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/qt/bitcoingui.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,7 @@ void BitcoinGUI::createTrayIconMenu()
860860
// Note: On macOS, the Dock icon is used to provide the tray's functionality.
861861
MacDockIconHandler* dockIconHandler = MacDockIconHandler::instance();
862862
connect(dockIconHandler, &MacDockIconHandler::dockIconClicked, [this] {
863+
if (m_node.shutdownRequested()) return; // nothing to show, node is shutting down.
863864
show();
864865
activateWindow();
865866
});
@@ -871,6 +872,8 @@ void BitcoinGUI::createTrayIconMenu()
871872
// See https://bugreports.qt.io/browse/QTBUG-91697
872873
trayIconMenu.get(), &QMenu::aboutToShow,
873874
[this, show_hide_action, send_action, receive_action, sign_action, verify_action, options_action, node_window_action, quit_action] {
875+
if (m_node.shutdownRequested()) return; // nothing to do, node is shutting down.
876+
874877
if (show_hide_action) show_hide_action->setText(
875878
(!isHidden() && !isMinimized() && !GUIUtil::isObscured(this)) ?
876879
tr("&Hide") :

0 commit comments

Comments
 (0)