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.
Another cause of crashes stems from the shortcuts provided by the appMenuBar
submenus during shutdown. For instance, executing actions like opening the information dialog (command + I) or the console dialog (command + T) lead to access null pointers. The second commit addresses and resolves these issues.
Basically, in the present setup, we create a parentless appMenuBar
whose submenus QActions
are connected to qApp
events (the app’s global instance). However, at the BitcoinGUI
destructor, we manually destruct this object without properly disconnecting the events. This leaves qApp
events, such as focusWindowChanged
, tied to submenus’ QAction
pointers, which causes the app to crash when it attempts to access them.
Important Note: This happened to me few times. The worst consequence was an inconsistent chain state during IBD. Which triggered a full “replay blocks” process on the next startup. Which was painfully slow.