History

Application: prevent crash on startup when "Interface Crashed" dialog is shown.

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.

Anthony J. Thibault committed 10 years ago

Commit a8bc8a71 parent 35aa0743 files · +9 −4Browse files

Showing the changes to interface/src/Menu.cpp (1 of 3 files). Show all

Unified · Split

interface/src/Menu.cpp+1−1
@@ -46,7 +46,7 @@ · 45 unmodified lines
46#include "Menu.h"46#include "Menu.h"
47 47
48Menu* Menu::getInstance() {48Menu* Menu::getInstance() {
49 return static_cast<Menu*>(qApp->getWindow()->menuBar());49 return dynamic_cast<Menu*>(qApp->getWindow()->menuBar());
50}50}
51 51
52Menu::Menu() {52Menu::Menu() {