diff --git a/src/plugins/simulator/fsxcommon/simconnectobject.cpp b/src/plugins/simulator/fsxcommon/simconnectobject.cpp index 893a6d006..90acd3ec1 100644 --- a/src/plugins/simulator/fsxcommon/simconnectobject.cpp +++ b/src/plugins/simulator/fsxcommon/simconnectobject.cpp @@ -286,7 +286,8 @@ namespace BlackSimPlugin CCallsignSet CSimConnectObjects::getAllCallsigns(bool withoutProbes) const { - if (!withoutProbes) { return CCallsignSet(this->keys()); } + if (this->isEmpty()) { return CCallsignSet(); } + if (!withoutProbes) { return CCallsignSet(this->keys()); } CCallsignSet callsigns; for (const CSimConnectObject &simObject : this->values()) { diff --git a/src/plugins/simulator/fsxcommon/simulatorfsxcommon.cpp b/src/plugins/simulator/fsxcommon/simulatorfsxcommon.cpp index 44118b556..27abe9a31 100644 --- a/src/plugins/simulator/fsxcommon/simulatorfsxcommon.cpp +++ b/src/plugins/simulator/fsxcommon/simulatorfsxcommon.cpp @@ -65,12 +65,12 @@ namespace BlackSimPlugin Q_ASSERT_X(remoteAircraftProvider, Q_FUNC_INFO, "Missing provider"); Q_ASSERT_X(sApp, Q_FUNC_INFO, "Missing global object"); - m_addPendingSimObjTimer.setInterval(AddPendingAircraftIntervalMs); + m_simObjectTimer.setInterval(AddPendingAircraftIntervalMs); m_useFsuipc = false; // default model will be set in derived class CSimulatorFsxCommon::registerHelp(); - connect(&m_addPendingSimObjTimer, &QTimer::timeout, this, &CSimulatorFsxCommon::addPendingAircraftByTimer); + connect(&m_simObjectTimer, &QTimer::timeout, this, &CSimulatorFsxCommon::timerBasedObjectAddOrRemove); } CSimulatorFsxCommon::~CSimulatorFsxCommon() @@ -990,9 +990,10 @@ namespace BlackSimPlugin } } - void CSimulatorFsxCommon::addPendingAircraftByTimer() + void CSimulatorFsxCommon::timerBasedObjectAddOrRemove() { this->addPendingAircraft(AddByTimer); + this->physicallyRemoveAircraftNotInProvider(); } void CSimulatorFsxCommon::addPendingAircraftAfterAdded() @@ -1281,7 +1282,7 @@ namespace BlackSimPlugin Q_ASSERT_X(newRemoteAircraft.hasModelString(), Q_FUNC_INFO, "missing model string"); // reset timer - m_addPendingSimObjTimer.start(AddPendingAircraftIntervalMs); // restart + m_simObjectTimer.start(AddPendingAircraftIntervalMs); // restart const CSimConnectObjects outdatedAdded = m_simConnectObjects.removeOutdatedPendingAdded(CSimConnectObject::AllTypes); if (!outdatedAdded.isEmpty()) @@ -1526,12 +1527,7 @@ namespace BlackSimPlugin } // cleanup function, actually this should not be needed - const QPointer myself(this); - QTimer::singleShot(100, this, [ = ] - { - if (!myself) { return; } - CSimulatorFsxCommon::physicallyRemoveAircraftNotInProvider(); - }); + this->physicallyRemoveAircraftNotInProviderAsync(); // bye return true; @@ -2130,6 +2126,7 @@ namespace BlackSimPlugin CCallsignSet CSimulatorFsxCommon::getCallsignsMissingInProvider() const { + if (m_simConnectObjects.isEmpty()) { return CCallsignSet(); } const CCallsignSet simObjectCallsigns(m_simConnectObjects.getAllCallsigns(true)); const CCallsignSet providerCallsigns(this->getAircraftInRangeCallsigns()); return simObjectCallsigns.difference(providerCallsigns); @@ -2312,6 +2309,16 @@ namespace BlackSimPlugin return callsignsToBeRemoved; } + void CSimulatorFsxCommon::physicallyRemoveAircraftNotInProviderAsync() + { + const QPointer myself(this); + QTimer::singleShot(100, this, [ = ] + { + if (!myself || !sApp || sApp->isShuttingDown()) { return; } + CSimulatorFsxCommon::physicallyRemoveAircraftNotInProvider(); + }); + } + CSimulatorFsxCommonListener::CSimulatorFsxCommonListener(const CSimulatorPluginInfo &info) : ISimulatorListener(info) { diff --git a/src/plugins/simulator/fsxcommon/simulatorfsxcommon.h b/src/plugins/simulator/fsxcommon/simulatorfsxcommon.h index 3903df10f..94fb7a3f2 100644 --- a/src/plugins/simulator/fsxcommon/simulatorfsxcommon.h +++ b/src/plugins/simulator/fsxcommon/simulatorfsxcommon.h @@ -294,9 +294,12 @@ namespace BlackSimPlugin int physicallyInitAITerrainProbes(const BlackMisc::Geo::ICoordinateGeodetic &coordinate, int number); //! Remove aircraft no longer in provider - //! \remark kind of cleanup function, in an ideal this should never need to cleanup something + //! \remark kind of cleanup function, in an ideal scenario this should never need to cleanup something BlackMisc::Aviation::CCallsignSet physicallyRemoveAircraftNotInProvider(); + //! ASynchronous version of physicallyRemoveAircraftNotInProvider + void physicallyRemoveAircraftNotInProviderAsync(); + //! Verify that an object has been added in simulator //! \remark checks if the object was really added after an "add request" and not directly removed again //! \remark requests further data on remote aircraft (lights, ..) when correctly added @@ -315,7 +318,7 @@ namespace BlackSimPlugin void verifyAddedTerrainProbe(const BlackMisc::Simulation::CSimulatedAircraft &remoteAircraftIn); //! Add next aircraft based on timer - void addPendingAircraftByTimer(); + void timerBasedObjectAddOrRemove(); //! Add next aircraft after another has been confirmed void addPendingAircraftAfterAdded(); @@ -549,7 +552,7 @@ namespace BlackSimPlugin CSimConnectObjects m_addPendingAircraft; //!< aircraft/probes awaiting to be added; SIMCONNECT_DATA_REQUEST_ID m_requestIdSimObjAircraft = static_cast(RequestSimObjAircraftStart); //!< request id, use obtainRequestIdForSimObjAircraft to get id SIMCONNECT_DATA_REQUEST_ID m_requestIdSimObjTerrainProbe = static_cast(RequestSimObjTerrainProbeStart); //!< request id, use obtainRequestIdForSimObjTerrainProbe to get id - QTimer m_addPendingSimObjTimer; //!< updating of SimObjects awaiting to be added + QTimer m_simObjectTimer; //!< updating of SimObjects awaiting to be added //! Request id to string static QString requestIdToString(DWORD requestId);