1
0
Fork 0

Traffic: Improve iterator robustness

Attempting to fix Sentry crash FLIGHTGEAR-B, crash on shutdown. Not
sure this is quite right, but the logic is clearer and we handle
invalid iterators better.
This commit is contained in:
James Turner 2020-08-23 22:45:50 +01:00
parent c6182af080
commit 4fe8a118cc
2 changed files with 25 additions and 26 deletions

View file

@ -1046,34 +1046,30 @@ void FGTowerController::signOff(int id)
{ {
// Search activeTraffic for a record matching our id // Search activeTraffic for a record matching our id
TrafficVectorIterator i = searchActiveTraffic(activeTraffic, id); TrafficVectorIterator i = searchActiveTraffic(activeTraffic, id);
if (i == activeTraffic.end() || (activeTraffic.empty())) {
SG_LOG(SG_ATC, SG_ALERT,
"AI error: Aircraft without traffic record is signing off from tower at " << SG_ORIGIN);
return;
}
// If this aircraft has left the runway, we can clear the departure record for this runway const auto trafficRunway = i->getRunway();
ActiveRunwayVecIterator rwy = activeRunways.begin(); auto runwayIt = std::find_if(activeRunways.begin(), activeRunways.end(),
if (! activeRunways.empty()) { [&trafficRunway](const ActiveRunway& ar) {
//while ((rwy->getRunwayName() != i->getRunway()) && (rwy != activeRunways.end())) { return ar.getRunwayName() == trafficRunway;
while (rwy != activeRunways.end()) { });
if (rwy->getRunwayName() == i->getRunway()) {
break; if (runwayIt != activeRunways.end()) {
} runwayIt->setCleared(0);
rwy++; runwayIt->updatedepartureQueue();
}
if (rwy != activeRunways.end()) {
rwy->setCleared(0);
rwy->updatedepartureQueue();
} else { } else {
SG_LOG(SG_ATC, SG_ALERT, SG_LOG(SG_ATC, SG_ALERT,
"AI error: Attempting to erase non-existing runway clearance record in FGTowerController::signoff at " << SG_ORIGIN); "AI error: Attempting to erase non-existing runway clearance record in FGTowerController::signoff at " << SG_ORIGIN);
} }
}
if (i == activeTraffic.end() || (activeTraffic.empty())) {
SG_LOG(SG_ATC, SG_ALERT,
"AI error: Aircraft without traffic record is signing off from tower at " << SG_ORIGIN);
} else {
i->getAircraft()->resetTakeOffStatus(); i->getAircraft()->resetTakeOffStatus();
i = activeTraffic.erase(i); activeTraffic.erase(i);
SG_LOG(SG_ATC, SG_DEBUG, "Signing off from tower controller"); SG_LOG(SG_ATC, SG_DEBUG, "Signing off from tower controller");
} }
}
// NOTE: // NOTE:
// IF WE MAKE TRAFFICRECORD A MEMBER OF THE BASE CLASS // IF WE MAKE TRAFFICRECORD A MEMBER OF THE BASE CLASS

View file

@ -331,13 +331,16 @@ public:
distanceToFinal = 6.0 * SG_NM_TO_METER; distanceToFinal = 6.0 * SG_NM_TO_METER;
}; };
std::string getRunwayName() { const std::string& getRunwayName() const
{
return rwy; return rwy;
}; };
int getCleared () { int getCleared() const
{
return currentlyCleared; return currentlyCleared;
}; };
double getApproachDistance() { const double getApproachDistance() const
{
return distanceToFinal; return distanceToFinal;
}; };
//time_t getEstApproachTime() { return estimatedArrival; }; //time_t getEstApproachTime() { return estimatedArrival; };