From 8b7f03584211a4233f9891f5b4025e63810dfbe1 Mon Sep 17 00:00:00 2001 From: DonLakeFlyer Date: Tue, 10 Apr 2018 21:41:45 -0700 Subject: [PATCH] Fix crash from bad toolbox reference during shutdown --- src/QmlControls/AppMessages.cc | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/src/QmlControls/AppMessages.cc b/src/QmlControls/AppMessages.cc index 9931e593f..dc9db5f07 100644 --- a/src/QmlControls/AppMessages.cc +++ b/src/QmlControls/AppMessages.cc @@ -92,25 +92,23 @@ void AppLogModel::threadsafeLog(const QString message) insertRows(line, 1); setData(index(line), message, Qt::DisplayRole); - if (qgcApp()->logOutput()) { - if (_logFile.fileName().isEmpty()) { - QGCToolbox* toolbox = qgcApp()->toolbox(); - // Be careful of toolbox not being open yet - if (toolbox) { - QString saveDirPath = qgcApp()->toolbox()->settingsManager()->appSettings()->crashSavePath(); - QDir saveDir(saveDirPath); - QString saveFilePath = saveDir.absoluteFilePath(QStringLiteral("QGCConsole.log")); - - _logFile.setFileName(saveFilePath); - if (!_logFile.open(QIODevice::WriteOnly | QIODevice::Text)) { - qgcApp()->showMessage(tr("Open console log output file failed %1 : %2").arg(_logFile.fileName()).arg(_logFile.errorString())); - } + if (_logFile.fileName().isEmpty() && qgcApp()->logOutput()) { + QGCToolbox* toolbox = qgcApp()->toolbox(); + // Be careful of toolbox not being open yet + if (toolbox) { + QString saveDirPath = qgcApp()->toolbox()->settingsManager()->appSettings()->crashSavePath(); + QDir saveDir(saveDirPath); + QString saveFilePath = saveDir.absoluteFilePath(QStringLiteral("QGCConsole.log")); + + _logFile.setFileName(saveFilePath); + if (!_logFile.open(QIODevice::WriteOnly | QIODevice::Text)) { + qgcApp()->showMessage(tr("Open console log output file failed %1 : %2").arg(_logFile.fileName()).arg(_logFile.errorString())); } } + } - if (_logFile.isOpen()) { - QTextStream out(&_logFile); - out << message << "\n"; - } + if (_logFile.isOpen()) { + QTextStream out(&_logFile); + out << message << "\n"; } } -- 2.22.0