I had massive problems with tower.cxx, so I decided to doublecheck all
containers and iterators in order and found lot of potential problems.
Now I can fly with "debug on" of KSFO for minutes without problems.
The fix for AIMgr is from Mathias, but I reworked it. So blame me, not him.
string s = (*apt_itr).first;
if(traffic.find(s) != traffic.end()) {
//cout << "s = " << s << ", traffic[s].size() = " << traffic[s].size() << '\n';
string s = (*apt_itr).first;
if(traffic.find(s) != traffic.end()) {
//cout << "s = " << s << ", traffic[s].size() = " << traffic[s].size() << '\n';
- if(traffic[s].size()) {
+ if(!traffic[s].empty()) {
apt_itr++;
} else {
//cout << "Erasing " << (*apt_itr).first << " and traffic" << '\n';
apt_itr++;
} else {
//cout << "Erasing " << (*apt_itr).first << " and traffic" << '\n';
- activated.erase(apt_itr++);
+ activated.erase(apt_itr);
+ apt_itr = activated.upper_bound(s);
traffic.erase(s);
}
} else {
//cout << "Erasing " << (*apt_itr).first << ' ' << (*apt_itr).second << '\n';
traffic.erase(s);
}
} else {
//cout << "Erasing " << (*apt_itr).first << ' ' << (*apt_itr).second << '\n';
- activated.erase(apt_itr++);
+ activated.erase(apt_itr);
+ apt_itr = activated.upper_bound(s);
t->planePtr = NULL;
t->clearedToTakeOff = true;
rwyList.push_back(t);
t->planePtr = NULL;
t->clearedToTakeOff = true;
rwyList.push_back(t);
+ rwyListItr = rwyList.begin();
departed = false;
} else {
//cout << "User not on active runway\n";
departed = false;
} else {
//cout << "User not on active runway\n";
ClearHoldingPlane(t);
t->leg = TAKEOFF_ROLL;
rwyList.push_back(t);
ClearHoldingPlane(t);
t->leg = TAKEOFF_ROLL;
rwyList.push_back(t);
+ rwyListItr = rwyList.begin();
rwyOccupied = true;
// WARNING - WE ARE ASSUMING ONLY ONE PLANE REPORTING HOLD AT A TIME BELOW
// FIXME TODO - FIX THIS!!!
rwyOccupied = true;
// WARNING - WE ARE ASSUMING ONLY ONE PLANE REPORTING HOLD AT A TIME BELOW
// FIXME TODO - FIX THIS!!!
+ if(!holdList.empty()) {
if(holdListItr == holdList.end()) {
holdListItr = holdList.begin();
}
if(holdListItr == holdList.end()) {
holdListItr = holdList.begin();
}
// This assumes that the number spoken is landing position, not circuit position, since some of the traffic might be on straight-in final.
trns += " ";
TowerPlaneRec* tt = NULL;
// This assumes that the number spoken is landing position, not circuit position, since some of the traffic might be on straight-in final.
trns += " ";
TowerPlaneRec* tt = NULL;
- if((i == 1) && (!rwyList.size()) && (t->nextOnRwy) && (!cf)) { // Unfortunately nextOnRwy currently doesn't handle circuit/straight-in ordering properly at present, hence the cf check below.
+ if((i == 1) && rwyList.empty() && (t->nextOnRwy) && (!cf)) { // Unfortunately nextOnRwy currently doesn't handle circuit/straight-in ordering properly at present, hence the cf check below.
trns += "Cleared to land"; // TODO - clear for the option if appropriate
t->clearedToLand = true;
if(!t->isUser) t->planePtr->RegisterTransmission(7);
trns += "Cleared to land"; // TODO - clear for the option if appropriate
t->clearedToLand = true;
if(!t->isUser) t->planePtr->RegisterTransmission(7);
// Do one plane from the hold list
void FGTower::CheckHoldList(double dt) {
//cout << "Entering CheckHoldList..." << endl;
// Do one plane from the hold list
void FGTower::CheckHoldList(double dt) {
//cout << "Entering CheckHoldList..." << endl;
+ if(!holdList.empty()) {
//cout << "*holdListItr = " << *holdListItr << endl;
if(holdListItr == holdList.end()) {
holdListItr = holdList.begin();
//cout << "*holdListItr = " << *holdListItr << endl;
if(holdListItr == holdList.end()) {
holdListItr = holdList.begin();
ClearHoldingPlane(t);
t->leg = TAKEOFF_ROLL;
rwyList.push_back(t);
ClearHoldingPlane(t);
t->leg = TAKEOFF_ROLL;
rwyList.push_back(t);
+ rwyListItr = rwyList.begin();
rwyOccupied = true;
holdList.erase(holdListItr);
holdListItr = holdList.begin();
rwyOccupied = true;
holdList.erase(holdListItr);
holdListItr = holdList.begin();
+ if (holdList.empty())
+ return;
}
}
// TODO - rationalise the considerable code duplication above!
}
}
// TODO - rationalise the considerable code duplication above!
downwind_leg_pos = 0.0;
crosswind_leg_pos = 0.0;
downwind_leg_pos = 0.0;
crosswind_leg_pos = 0.0;
- if(circuitList.size()) { // Do one plane from the circuit
+ if(!circuitList.empty()) { // Do one plane from the circuit
if(circuitListItr == circuitList.end()) {
circuitListItr = circuitList.begin();
}
if(circuitListItr == circuitList.end()) {
circuitListItr = circuitList.begin();
}
t->opType = OUTBOUND; // TODO - could check if the user has climbed significantly above circuit altitude as well.
// Since we are unknown operation we should be in depList already.
//cout << ident << " Removing user from circuitList (TTT_UNKNOWN)\n";
t->opType = OUTBOUND; // TODO - could check if the user has climbed significantly above circuit altitude as well.
// Since we are unknown operation we should be in depList already.
//cout << ident << " Removing user from circuitList (TTT_UNKNOWN)\n";
- circuitList.erase(circuitListItr);
+ circuitListItr = circuitList.erase(circuitListItr);
RemoveFromTrafficList(t->plane.callsign);
RemoveFromTrafficList(t->plane.callsign);
- circuitListItr = circuitList.begin();
+ if (circuitList.empty())
+ return;
}
} else if(t->opType == CIRCUIT) {
if(tortho.y() > 10000) {
// 10 km out - assume the user has abandoned the circuit!!
t->opType = OUTBOUND;
depList.push_back(t);
}
} else if(t->opType == CIRCUIT) {
if(tortho.y() > 10000) {
// 10 km out - assume the user has abandoned the circuit!!
t->opType = OUTBOUND;
depList.push_back(t);
+ depListItr = depList.begin();
//cout << ident << " removing user from circuitList (CIRCUIT)\n";
//cout << ident << " removing user from circuitList (CIRCUIT)\n";
- circuitList.erase(circuitListItr);
- circuitListItr = circuitList.begin();
+ circuitListItr = circuitList.erase(circuitListItr);
+ if (circuitList.empty())
+ return;
// It's possible we could be a bit more proactive about this.
} else if(t->opType == OUTBOUND) {
depList.push_back(t);
// It's possible we could be a bit more proactive about this.
} else if(t->opType == OUTBOUND) {
depList.push_back(t);
+ depListItr = depList.begin();
rwyList.pop_front();
departed = true;
timeSinceLastDeparture = 0.0;
} else if(t->opType == CIRCUIT) {
//cout << ident << " adding " << t->plane.callsign << " to circuitList" << endl;
circuitList.push_back(t);
rwyList.pop_front();
departed = true;
timeSinceLastDeparture = 0.0;
} else if(t->opType == CIRCUIT) {
//cout << ident << " adding " << t->plane.callsign << " to circuitList" << endl;
circuitList.push_back(t);
+ circuitListItr = circuitList.begin();
AddToTrafficList(t);
rwyList.pop_front();
departed = true;
timeSinceLastDeparture = 0.0;
} else if(t->opType == TTT_UNKNOWN) {
depList.push_back(t);
AddToTrafficList(t);
rwyList.pop_front();
departed = true;
timeSinceLastDeparture = 0.0;
} else if(t->opType == TTT_UNKNOWN) {
depList.push_back(t);
+ depListItr = depList.begin();
//cout << ident << " adding " << t->plane.callsign << " to circuitList" << endl;
circuitList.push_back(t);
//cout << ident << " adding " << t->plane.callsign << " to circuitList" << endl;
circuitList.push_back(t);
+ circuitListItr = circuitList.begin();
AddToTrafficList(t);
rwyList.pop_front();
departed = true;
AddToTrafficList(t);
rwyList.pop_front();
departed = true;
void FGTower::CheckApproachList(double dt) {
//cout << "CheckApproachList called for " << ident << endl;
//cout << "AppList.size is " << appList.size() << endl;
void FGTower::CheckApproachList(double dt) {
//cout << "CheckApproachList called for " << ident << endl;
//cout << "AppList.size is " << appList.size() << endl;
if(appListItr == appList.end()) {
appListItr = appList.begin();
}
if(appListItr == appList.end()) {
appListItr = appList.begin();
}
if(appListItr == appList.end() ) {
appListItr = appList.begin();
}
if(appListItr == appList.end() ) {
appListItr = appList.begin();
}
+ if (appList.empty())
+ return;
+
// Do one plane from the departure list
void FGTower::CheckDepartureList(double dt) {
// Do one plane from the departure list
void FGTower::CheckDepartureList(double dt) {
if(depListItr == depList.end()) {
depListItr = depList.begin();
}
if(depListItr == depList.end()) {
depListItr = depList.begin();
}
// It depends on what the two planes are doing and whether there's a conflict what we do.
if(tpr->eta - t->eta > separation_time) { // No probs, plane 2 can squeeze in before plane 1 with no apparent conflict
circuitList.insert(twrItr, t);
// It depends on what the two planes are doing and whether there's a conflict what we do.
if(tpr->eta - t->eta > separation_time) { // No probs, plane 2 can squeeze in before plane 1 with no apparent conflict
circuitList.insert(twrItr, t);
+ circuitListItr = circuitList.begin();
} else { // Ooops - this ones tricky - we have a potential conflict!
conflict = true;
// HACK - just add anyway for now and flag conflict.
circuitList.insert(twrItr, t);
} else { // Ooops - this ones tricky - we have a potential conflict!
conflict = true;
// HACK - just add anyway for now and flag conflict.
circuitList.insert(twrItr, t);
+ circuitListItr = circuitList.begin();
}
//cout << "\tC\t" << circuitList.size() << '\n';
return(conflict);
}
//cout << "\tC\t" << circuitList.size() << '\n';
return(conflict);
// If we get here we must be at the end of the list, or maybe the list is empty.
//cout << ident << " adding " << t->plane.callsign << " to circuitList" << endl;
circuitList.push_back(t); // TODO - check the separation with the preceding plane for the conflict flag.
// If we get here we must be at the end of the list, or maybe the list is empty.
//cout << ident << " adding " << t->plane.callsign << " to circuitList" << endl;
circuitList.push_back(t); // TODO - check the separation with the preceding plane for the conflict flag.
+ circuitListItr = circuitList.begin();
//cout << "\tE\t" << circuitList.size() << endl;
return(conflict);
}
//cout << "\tE\t" << circuitList.size() << endl;
return(conflict);
}
responseReqd = true;
appList.push_back(t); // Not necessarily permanent
responseReqd = true;
appList.push_back(t); // Not necessarily permanent
+ appListItr = appList.begin();
AddToTrafficList(t);
current_atcdialog->remove_entry(ident, USER_REQUEST_VFR_ARRIVAL, TOWER);
AddToTrafficList(t);
current_atcdialog->remove_entry(ident, USER_REQUEST_VFR_ARRIVAL, TOWER);
//cout << "Before adding, appList.size = " << appList.size() << " at " << ident << '\n';
appList.push_back(t); // Not necessarily permanent
//cout << "Before adding, appList.size = " << appList.size() << " at " << ident << '\n';
appList.push_back(t); // Not necessarily permanent
+ appListItr = appList.begin();
//cout << "After adding, appList.size = " << appList.size() << " at " << ident << '\n';
AddToTrafficList(t);
}
//cout << "After adding, appList.size = " << appList.size() << " at " << ident << '\n';
AddToTrafficList(t);
}