diff --git a/src/comm/QGCFlightGearLink.cc b/src/comm/QGCFlightGearLink.cc index 5373d36664ba942a2e22d2b77f24f1216bf2b66f..68e8d9d5d4ed5a0a59f4b2225a64447f2e9f5053 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 ed83adafe11ff428249968bba952eceba9cdfe43..57bb641439dbbc8fb52c8145dfd4276f892d30a0 100644 --- a/src/comm/QGCHilLink.h +++ b/src/comm/QGCHilLink.h @@ -83,6 +83,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 **/ diff --git a/src/uas/UAS.cc b/src/uas/UAS.cc index 68c5fb6f68e3628ed1b126bd527babe371b069cf..db4799e3d6a2c77db7428b055751b5ec04a37d83 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."; }