From d89f6b7994d128720d16b566fd244f91fd476469 Mon Sep 17 00:00:00 2001 From: Don Gagne Date: Fri, 24 Feb 2017 09:55:20 -0800 Subject: [PATCH] Fix shutdown crash --- src/QGCApplication.cc | 11 ++++++++++- src/QGCApplication.h | 6 ++++++ src/main.cc | 1 + 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/QGCApplication.cc b/src/QGCApplication.cc index a92a4ed..2e35130 100644 --- a/src/QGCApplication.cc +++ b/src/QGCApplication.cc @@ -334,8 +334,12 @@ QGCApplication::QGCApplication(int &argc, char* argv[], bool unitTesting) _toolbox->setChildToolboxes(); } -QGCApplication::~QGCApplication() +void QGCApplication::_shutdown(void) { + // This code is specifically not in the destructor since the application object may not be available in the destructor. + // This cause problems for deleting object like settings which are in the toolbox which may have qml references. By + // moving them here and having main.cc call this prior to deleting the app object we make sure app object is still + // around while these things are shutting down. #ifndef __mobile__ MainWindow* mainWindow = MainWindow::instance(); if (mainWindow) { @@ -346,6 +350,11 @@ QGCApplication::~QGCApplication() delete _toolbox; } +QGCApplication::~QGCApplication() +{ + // Place shutdown code in _shutdown +} + void QGCApplication::_initCommon(void) { QSettings settings; diff --git a/src/QGCApplication.h b/src/QGCApplication.h index c080b24..f5234c5 100644 --- a/src/QGCApplication.h +++ b/src/QGCApplication.h @@ -152,6 +152,12 @@ public: static QGCApplication* _app; ///< Our own singleton. Should be reference directly by qgcApp +public: + // Although public, these methods are internal and should only be called by UnitTest code + + /// Shutdown the application object + void _shutdown(void); + private slots: void _missingParamsDisplay(void); diff --git a/src/main.cc b/src/main.cc index 4dec260..8c2ff2d 100644 --- a/src/main.cc +++ b/src/main.cc @@ -253,6 +253,7 @@ int main(int argc, char *argv[]) exitCode = app->exec(); } + app->_shutdown(); delete app; //-- Shutdown Cache System destroyMapEngine();