diff --git a/src/plugins/simulator/fsxcommon/simconnectobject.cpp b/src/plugins/simulator/fsxcommon/simconnectobject.cpp index ed565d4be..d6dbf95cd 100644 --- a/src/plugins/simulator/fsxcommon/simconnectobject.cpp +++ b/src/plugins/simulator/fsxcommon/simconnectobject.cpp @@ -7,6 +7,7 @@ * contained in the LICENSE file. */ +#include "simconnectobject.h" #include "simconnectobject.h" #include "blackmisc/simulation/interpolatormulti.h" @@ -128,6 +129,11 @@ namespace BlackSimPlugin return getSimObjectForObjectId(objectId).getCallsign(); } + CCallsignSet CSimConnectObjects::getAllCallsigns() const + { + return CCallsignSet(this->keys()); + } + CSimConnectObject CSimConnectObjects::getSimObjectForObjectId(DWORD objectId) const { for (const CSimConnectObject &simObject : this->values()) diff --git a/src/plugins/simulator/fsxcommon/simconnectobject.h b/src/plugins/simulator/fsxcommon/simconnectobject.h index 6761f5ebd..3753503e5 100644 --- a/src/plugins/simulator/fsxcommon/simconnectobject.h +++ b/src/plugins/simulator/fsxcommon/simconnectobject.h @@ -186,6 +186,9 @@ namespace BlackSimPlugin //! Number of pending removed int countPendingRemoved() const; + //! Get all callsigns + BlackMisc::Aviation::CCallsignSet getAllCallsigns() const; + //! Callsigns of pending added callsigns BlackMisc::Aviation::CCallsignSet getPendingAddedCallsigns() const; diff --git a/src/plugins/simulator/fsxcommon/simulatorfsxcommon.cpp b/src/plugins/simulator/fsxcommon/simulatorfsxcommon.cpp index 2d71b7b21..d7928595a 100644 --- a/src/plugins/simulator/fsxcommon/simulatorfsxcommon.cpp +++ b/src/plugins/simulator/fsxcommon/simulatorfsxcommon.cpp @@ -915,7 +915,11 @@ namespace BlackSimPlugin // call in SIM const SIMCONNECT_DATA_REQUEST_ID requestId = this->obtainRequestIdForSimData(); const HRESULT result = SimConnect_AIRemoveObject(m_hSimConnect, static_cast(simObject.getObjectId()), requestId); - if (result != S_OK) + if (result == S_OK) + { + if (m_traceSendId) { this->traceSendId(simObject.getObjectId(), Q_FUNC_INFO);} + } + else { CLogMessage(this).warning("Removing aircraft '%1' from simulator failed") << callsign.asString(); } @@ -938,14 +942,19 @@ namespace BlackSimPlugin int CSimulatorFsxCommon::physicallyRemoveAllRemoteAircraft() { - if (m_simConnectObjects.isEmpty()) { return 0; } - const QList callsigns(m_simConnectObjects.keys()); + // make sure they are not added again + // cleaning here is somewhat redundant, but double checks + m_addPendingAircraft.clear(); + m_addAgainAircraftWhenRemoved.clear(); + + // remove one by one int r = 0; + const CCallsignSet callsigns = m_simConnectObjects.getAllCallsigns(); for (const CCallsign &cs : callsigns) { - if (physicallyRemoveRemoteAircraft(cs)) { r++; } + if (this->physicallyRemoveRemoteAircraft(cs)) { r++; } } - clearAllAircraft(); + this->clearAllAircraft(); return r; }