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/Application.cpp (1 of 3 files). Show all

Unified · Split

interface/src/Application.cpp+6−1
@@ -452,8 +452,8 @@ Q_GUI_EXPORT void qt_gl_set_global_share_context(QOpenGLContext *context); · 451 unmodified lines
452452
453453 Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) :
454454 QApplication(argc, argv),
455− _dependencyManagerIsSetup(setupEssentials(argc, argv)),
456455 _window(new MainWindow(desktop())),
456+ _dependencyManagerIsSetup(setupEssentials(argc, argv)),
457457 _undoStackScriptingInterface(&_undoStack),
458458 _frameCount(0),
459459 _fps(60.0f),
@@ -1744,6 +1744,11 @@ bool Application::importSVOFromURL(const QString& urlString) { · 1284 unmodified lines
17441744 }
17451745
17461746 bool Application::event(QEvent* event) {
1747+
1748+ if (!Menu::getInstance()) {
1749+ return false;
1750+ }
1751+
17471752 if ((int)event->type() == (int)Lambda) {
17481753 ((LambdaEvent*)event)->call();
17491754 return true;