If the application "Interface Crashed" dialog is shown at startup, it can cause Application to receive events before it has been fully constructed. In this case the QMainWindow _window pointer is uninitialized, causing Menu::getInstance() to de-reference an invalid pointer. The fix for this is three fold. 1. Construct the QMainWindow before calling setupEssentials (which in turn spawns the "Interface Crashed" dialog). 2. Change Menu::getInstance() from a static_cast to a dynamic_cast. This will cause it to return a nullptr if [QMainWindow::menuBar()](http://doc.qt.io/qt-4.8/qmainwindow.html#menuBar) returns an instance of QMenuBar and not a ui::Menu instance. 3. In Application::event return false if Menu::getInstance() returns a nullptr. This should prevent any code that relies on having a valid ui::Menu instance from running.
Showing the changes to interface/src/Menu.cpp (1 of 3 files). Show all
Unified · Split
| @@ -46,7 +46,7 @@ · 45 unmodified lines | ||
| 46 | 46 | #include "Menu.h" |
| 47 | 47 | |
| 48 | 48 | Menu* Menu::getInstance() { |
| 49 | − return static_cast<Menu*>(qApp->getWindow()->menuBar()); | |
| 49 | + return dynamic_cast<Menu*>(qApp->getWindow()->menuBar()); | |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | Menu::Menu() { |