From f34e80ea629f7d74771f4d87af7167a27a971364 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Thu, 13 Apr 2017 01:06:05 +0200 Subject: [PATCH] refs #935, avoid issues when shutting down --- src/blackcore/simulator.cpp | 8 +++++++- src/blackcore/simulator.h | 6 ++++++ src/blackcore/simulatorcommon.cpp | 5 +++++ src/blackcore/simulatorcommon.h | 1 + src/plugins/simulator/fsxcommon/simulatorfsxcommon.cpp | 2 +- 5 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/blackcore/simulator.cpp b/src/blackcore/simulator.cpp index 30aefa5bd..7bc3b1d87 100644 --- a/src/blackcore/simulator.cpp +++ b/src/blackcore/simulator.cpp @@ -8,6 +8,7 @@ */ #include "blackcore/simulator.h" +#include "blackcore/application.h" #include #include @@ -83,6 +84,11 @@ namespace BlackCore return m_info.toQString(); } + bool ISimulatorListener::isShuttingDown() const + { + return (!sApp || sApp->isShuttingDown()); + } + void ISimulatorListener::start() { if (m_isRunning) { return; } @@ -92,7 +98,7 @@ namespace BlackCore void ISimulatorListener::stop() { - if(!m_isRunning) { return; } + if (!m_isRunning) { return; } stopImpl(); m_isRunning = false; } diff --git a/src/blackcore/simulator.h b/src/blackcore/simulator.h index d1d897168..97061aaec 100644 --- a/src/blackcore/simulator.h +++ b/src/blackcore/simulator.h @@ -151,6 +151,9 @@ namespace BlackCore //! Driver will be unloaded virtual void unload() = 0; + //! Is overall (swift) application shutting down + virtual bool isShuttingDown() const = 0; + //! Set interpolation mode, empty callsign applies to all know callsigns virtual bool setInterpolatorMode(BlackMisc::Simulation::CInterpolatorMulti::Mode mode, const BlackMisc::Aviation::CCallsign &callsign) = 0; @@ -253,6 +256,9 @@ namespace BlackCore //! Info about the backend system (if available) virtual QString backendInfo() const; + //! Overall (swift) application shutting down + virtual bool isShuttingDown() const; + public slots: //! Start listening for the simulator to start. void start(); diff --git a/src/blackcore/simulatorcommon.cpp b/src/blackcore/simulatorcommon.cpp index 0625584fd..2eb4290de 100644 --- a/src/blackcore/simulatorcommon.cpp +++ b/src/blackcore/simulatorcommon.cpp @@ -291,6 +291,11 @@ namespace BlackCore this->m_remoteAircraftProviderConnections.disconnectAll(); // disconnect signals from provider } + bool CSimulatorCommon::isShuttingDown() const + { + return (!sApp || sApp->isShuttingDown()); + } + void CSimulatorCommon::setInterpolationAndRenderingSetup(const CInterpolationAndRenderingSetup &setup) { { diff --git a/src/blackcore/simulatorcommon.h b/src/blackcore/simulatorcommon.h index f093b8ae6..19b30d5c2 100644 --- a/src/blackcore/simulatorcommon.h +++ b/src/blackcore/simulatorcommon.h @@ -83,6 +83,7 @@ namespace BlackCore virtual BlackMisc::Aviation::CAirportList getAirportsInRange() const override; virtual void setWeatherActivated(bool activated) override; virtual void unload() override; + virtual bool isShuttingDown() const override; virtual int physicallyRemoveMultipleRemoteAircraft(const BlackMisc::Aviation::CCallsignSet &callsigns) override; //! \addtogroup swiftdotcommands diff --git a/src/plugins/simulator/fsxcommon/simulatorfsxcommon.cpp b/src/plugins/simulator/fsxcommon/simulatorfsxcommon.cpp index 7c3318afb..53d93d0d3 100644 --- a/src/plugins/simulator/fsxcommon/simulatorfsxcommon.cpp +++ b/src/plugins/simulator/fsxcommon/simulatorfsxcommon.cpp @@ -1356,7 +1356,7 @@ namespace BlackSimPlugin void CSimulatorFsxCommonListener::checkConnection() { - Q_ASSERT_X(sApp, Q_FUNC_INFO, "Missing sApp"); + if (this->isShuttingDown()) { return; } Q_ASSERT_X(!CThreadUtils::isCurrentThreadApplicationThread(), Q_FUNC_INFO, "Expect to run in background"); HANDLE hSimConnect; HRESULT result = SimConnect_Open(&hSimConnect, sApp->swiftVersionChar(), nullptr, 0, 0, 0);