From 17cebfb8d35610b33c836cec949e8e8b671d1fb0 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Mon, 20 Apr 2020 00:05:58 +0200 Subject: [PATCH] Ref T786, further checks (shutdown, empty values) --- src/blackcore/simulator.cpp | 6 +++--- src/plugins/simulator/fs9/simulatorfs9.cpp | 2 ++ src/plugins/simulator/fsxcommon/simulatorfsxcommon.cpp | 8 ++++++-- src/plugins/simulator/xplane/simulatorxplane.cpp | 3 +++ 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/blackcore/simulator.cpp b/src/blackcore/simulator.cpp index 2a53a94c1..c2270bc27 100644 --- a/src/blackcore/simulator.cpp +++ b/src/blackcore/simulator.cpp @@ -174,7 +174,7 @@ namespace BlackCore void ISimulator::reloadWeatherSettings() { // log crash info about weather - if (sApp && !sApp->isShuttingDown()) { CCrashHandler::instance()->crashAndLogAppendInfo(u"Simulator weather: " % boolToYesNo(m_isWeatherActivated)); } + if (this->isShuttingDown()) { CCrashHandler::instance()->crashAndLogAppendInfo(u"Simulator weather: " % boolToYesNo(m_isWeatherActivated)); } if (!m_isWeatherActivated) { return; } m_lastWeatherPosition.setNull(); const CWeatherScenario selectedWeatherScenario = m_weatherScenarioSettings.get(); @@ -196,7 +196,7 @@ namespace BlackCore } // log crash info about weather - if (sApp && !sApp->isShuttingDown()) { CCrashHandler::instance()->crashAndLogAppendInfo(selectedWeatherScenario.toQString(true)); } + if (this->isShuttingDown()) { CCrashHandler::instance()->crashAndLogAppendInfo(selectedWeatherScenario.toQString(true)); } } void ISimulator::clearAllRemoteAircraftData() @@ -1384,7 +1384,7 @@ namespace BlackCore const QPointer myself(this); QTimer::singleShot(t, this, [ = ] { - if (myself.isNull() || myself->isShuttingDown()) { return; } + if (!myself || myself->isShuttingDown()) { return; } this->displayLoggedSituationInSimulator(cs, stopLogging, times - 1); }); } diff --git a/src/plugins/simulator/fs9/simulatorfs9.cpp b/src/plugins/simulator/fs9/simulatorfs9.cpp index af53acfe6..b4b8e0562 100644 --- a/src/plugins/simulator/fs9/simulatorfs9.cpp +++ b/src/plugins/simulator/fs9/simulatorfs9.cpp @@ -467,6 +467,8 @@ namespace BlackSimPlugin void CSimulatorFs9::injectWeatherGrid(const CWeatherGrid &weatherGrid) { if (this->isShuttingDownOrDisconnected()) { return; } + if (weatherGrid.isEmpty()) { return; } + if (!CThreadUtils::isCurrentThreadObjectThread(this)) { BLACK_VERIFY_X(!CBuildConfig::isLocalDeveloperDebugBuild(), Q_FUNC_INFO, "Wrong thread"); diff --git a/src/plugins/simulator/fsxcommon/simulatorfsxcommon.cpp b/src/plugins/simulator/fsxcommon/simulatorfsxcommon.cpp index cd5bbdba7..5a7dff2f4 100644 --- a/src/plugins/simulator/fsxcommon/simulatorfsxcommon.cpp +++ b/src/plugins/simulator/fsxcommon/simulatorfsxcommon.cpp @@ -2395,6 +2395,8 @@ namespace BlackSimPlugin void CSimulatorFsxCommon::injectWeatherGrid(const CWeatherGrid &weatherGrid) { if (this->isShuttingDownOrDisconnected()) { return; } + if (weatherGrid.isEmpty()) { return; } + if (!CThreadUtils::isCurrentThreadObjectThread(this)) { BLACK_VERIFY_X(!CBuildConfig::isLocalDeveloperDebugBuild(), Q_FUNC_INFO, "Wrong thread"); @@ -2817,7 +2819,7 @@ namespace BlackSimPlugin QPointer myself(this); QTimer::singleShot(0, this, [ = ] { - if (!myself) { return; } + if (!myself || !sApp || sApp->isShuttingDown()) { return; } this->checkConnection(); }); } @@ -2837,13 +2839,15 @@ namespace BlackSimPlugin bool check = false; if (isOk(result)) { + // if we can connect, but not dispatch, it can mean a previously started FSX/P3D + // blocks remote calls -> RESTART for (int i = 0; !check && i < 3 && !this->isShuttingDown(); i++) { // result not always in first dispatch as we first have to obtain simulator name result = SimConnect_CallDispatch(hSimConnect, CSimulatorFsxCommonListener::SimConnectProc, this); if (isFailure(result)) { break; } // means serious failure check = this->checkVersionAndSimulator(); - if (!check) { sApp->processEventsFor(500); } + if (!check && sApp) { sApp->processEventsFor(500); } } } SimConnect_Close(hSimConnect); diff --git a/src/plugins/simulator/xplane/simulatorxplane.cpp b/src/plugins/simulator/xplane/simulatorxplane.cpp index 0e6c0e661..6599e2410 100644 --- a/src/plugins/simulator/xplane/simulatorxplane.cpp +++ b/src/plugins/simulator/xplane/simulatorxplane.cpp @@ -897,8 +897,11 @@ namespace BlackSimPlugin void CSimulatorXPlane::injectWeatherGrid(const CWeatherGrid &weatherGrid) { if (this->isShuttingDownOrDisconnected()) { return; } + if (weatherGrid.isEmpty()) { return; } + if (!CThreadUtils::isCurrentThreadObjectThread(this)) { + BLACK_VERIFY_X(!CBuildConfig::isLocalDeveloperDebugBuild(), Q_FUNC_INFO, "Wrong thread"); QPointer myself(this); QTimer::singleShot(0, this, [ = ]