From 2040ff21c5d7489f0c8765962183052252823fbe Mon Sep 17 00:00:00 2001 From: Roland Winklmeier Date: Wed, 7 Sep 2016 00:34:00 +0200 Subject: [PATCH] Physically remove only physically rendered aircrafts Physically removing an aircraft which was not yet rendered or known is undefined behavior. In this particular case, adding an aircraft the first time caused its model to be updated, which called slot ISimulator::changeRemoteAircraftModel, trying to remove an aircraft which was not yet added and adding it again. This ends up in an endless loop. --- src/plugins/simulator/fscommon/simulatorfscommon.cpp | 4 +++- src/plugins/simulator/xplane/simulatorxplane.cpp | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/plugins/simulator/fscommon/simulatorfscommon.cpp b/src/plugins/simulator/fscommon/simulatorfscommon.cpp index ae0175110..b4e7fe130 100644 --- a/src/plugins/simulator/fscommon/simulatorfscommon.cpp +++ b/src/plugins/simulator/fscommon/simulatorfscommon.cpp @@ -109,7 +109,9 @@ namespace BlackSimPlugin bool CSimulatorFsCommon::changeRemoteAircraftModel(const CSimulatedAircraft &aircraft) { // remove upfront, and then enable / disable again - this->physicallyRemoveRemoteAircraft(aircraft.getCallsign()); + auto callsign = aircraft.getCallsign(); + if (!isPhysicallyRenderedAircraft(callsign)) { return false; } + this->physicallyRemoveRemoteAircraft(callsign); return this->changeRemoteAircraftEnabled(aircraft); } diff --git a/src/plugins/simulator/xplane/simulatorxplane.cpp b/src/plugins/simulator/xplane/simulatorxplane.cpp index 57e26acc8..e33fa3215 100644 --- a/src/plugins/simulator/xplane/simulatorxplane.cpp +++ b/src/plugins/simulator/xplane/simulatorxplane.cpp @@ -532,7 +532,9 @@ namespace BlackSimPlugin bool CSimulatorXPlane::changeRemoteAircraftModel(const CSimulatedAircraft &aircraft) { // remove upfront, and then enable / disable again - this->physicallyRemoveRemoteAircraft(aircraft.getCallsign()); + auto callsign = aircraft.getCallsign(); + if (!isPhysicallyRenderedAircraft(callsign)) { return false; } + this->physicallyRemoveRemoteAircraft(callsign); return this->changeRemoteAircraftEnabled(aircraft); }