From 5ddd7d6adbae6ab5e39e8078bcd6e32697ac1312 Mon Sep 17 00:00:00 2001 From: Nate Weibley Date: Wed, 26 Aug 2015 10:12:31 -0400 Subject: [PATCH] Fix thread unsafe simulator shutdown. Use a signal/slot connection to execute on correct thread --- src/comm/QGCFlightGearLink.cc | 5 +++-- src/comm/QGCHilLink.h | 5 +++++ src/uas/UAS.cc | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/comm/QGCFlightGearLink.cc b/src/comm/QGCFlightGearLink.cc index 5373d36..68e8d9d 100644 --- a/src/comm/QGCFlightGearLink.cc +++ b/src/comm/QGCFlightGearLink.cc @@ -70,6 +70,7 @@ QGCFlightGearLink::QGCFlightGearLink(UASInterface* mav, QString startupArguments // We need a mechanism so show error message from our FGLink thread on the UI thread. This signal connection will do that for us. connect(this, &QGCFlightGearLink::showCriticalMessageFromThread, qgcApp(), &QGCApplication::criticalMessageBoxOnMainThread); + connect(this, &QGCFlightGearLink::disconnectSim, this, &QGCFlightGearLink::disconnectSimulation); } QGCFlightGearLink::~QGCFlightGearLink() @@ -496,13 +497,13 @@ bool QGCFlightGearLink::disconnectSimulation() if (_fgProcess) { _fgProcess->close(); - delete _fgProcess; + _fgProcess->deleteLater(); _fgProcess = NULL; } if (_udpCommSocket) { _udpCommSocket->close(); - delete _udpCommSocket; + _udpCommSocket->deleteLater(); _udpCommSocket = NULL; } diff --git a/src/comm/QGCHilLink.h b/src/comm/QGCHilLink.h index ed83ada..57bb641 100644 --- a/src/comm/QGCHilLink.h +++ b/src/comm/QGCHilLink.h @@ -84,6 +84,11 @@ signals: void simulationDisconnected(); /** + * @brief Thread safe signal to disconnect simulator from other threads + **/ + void disconnectSim(); + + /** * @brief This signal is emitted instantly when the link status changes **/ void simulationConnected(bool connected); diff --git a/src/uas/UAS.cc b/src/uas/UAS.cc index 68c5fb6..db4799e 100644 --- a/src/uas/UAS.cc +++ b/src/uas/UAS.cc @@ -3227,7 +3227,7 @@ void UAS::startHil() void UAS::stopHil() { if (simulation && simulation->isConnected()) { - simulation->disconnectSimulation(); + simulation->disconnectSim(); setMode(base_mode & ~MAV_MODE_FLAG_HIL_ENABLED, custom_mode); qDebug() << __FILE__ << __LINE__ << "HIL is onboard not enabled, trying to disable."; }