From 476d548da9bb3893e9a3d3783ec014d03b98fc2f Mon Sep 17 00:00:00 2001 From: edouard Date: Sat, 4 Dec 2010 17:39:32 +0000 Subject: [PATCH] Should hopefully make log/stop log operations more robust, as well as avoid crashing GCS upon exit in case the user did log during the session... git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@2192 ebee16cc-31ac-478f-84a7-5cbb03baadba --- ground/src/plugins/logging/loggingplugin.cpp | 29 +++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/ground/src/plugins/logging/loggingplugin.cpp b/ground/src/plugins/logging/loggingplugin.cpp index d0ddcbd4d..4a5ee9159 100644 --- a/ground/src/plugins/logging/loggingplugin.cpp +++ b/ground/src/plugins/logging/loggingplugin.cpp @@ -126,6 +126,24 @@ void LoggingThread::run() void LoggingThread::stopLogging() { QWriteLocker locker(&lock); + + // Disconnect all objects we registered with: + ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); + UAVObjectManager *objManager = pm->getObject(); + + QList< QList > list; + list = objManager->getObjects(); + QList< QList >::const_iterator i; + QList::const_iterator j; + + for (i = list.constBegin(); i != list.constEnd(); ++i) + { + for (j = (*i).constBegin(); j != (*i).constEnd(); ++j) + { + disconnect(*j, SIGNAL(objectUpdated(UAVObject*)), (LoggingThread*) this, SLOT(objectUpdated(UAVObject*))); + } + } + logFile.close(); qDebug() << "File closed"; quit(); @@ -216,7 +234,8 @@ LoggingPlugin::LoggingPlugin() : state(IDLE) LoggingPlugin::~LoggingPlugin() { - // Do nothing + if (loggingThread) + delete loggingThread; } /** @@ -227,6 +246,9 @@ bool LoggingPlugin::initialize(const QStringList& args, QString *errMsg) Q_UNUSED(args); Q_UNUSED(errMsg); + loggingThread = NULL; + + // Add Menu entry Core::ActionManager* am = Core::ICore::instance()->actionManager(); Core::ActionContainer* ac = am->actionContainer(Core::Constants::M_TOOLS); @@ -314,6 +336,9 @@ void LoggingPlugin::toggleReplay() void LoggingPlugin::startLogging(QString file) { qDebug() << "Logging to " << file; + // We have to delete the previous logging thread if is was still there! + if (loggingThread) + delete loggingThread; loggingThread = new LoggingThread(); if(loggingThread->openFile(file,this)) { @@ -359,6 +384,8 @@ void LoggingPlugin::startReplay(QString file) void LoggingPlugin::stopLogging() { emit stopLoggingSignal(); + disconnect( this,SIGNAL(stopLoggingSignal()),0,0); + }