{
int index = aIndex;
if (aIndex < 0) { // negative indices count the the end
- index = _route.size() - index;
+ index = _route.size() + index;
}
if ((index < 0) || (index >= numWaypts())) {
void FGRouteMgr::currentWaypointChanged()
{
- Waypt* cur = (_currentIndex<numWaypts()) ? currentWaypt() : NULL;
+ Waypt* cur = currentWaypt();
Waypt* next = nextWaypt();
wp0->getChild("id")->setStringValue(cur ? cur->ident() : "");
Waypt* FGRouteMgr::currentWaypt() const
{
+ if ((_currentIndex < 0) || (_currentIndex >= numWaypts()))
+ return NULL;
return wayptAtIndex(_currentIndex);
}
Waypt* FGRouteMgr::nextWaypt() const
{
- if ((_currentIndex + 1) >= numWaypts()) {
+ if ((_currentIndex < 0) || ((_currentIndex + 1) >= numWaypts())) {
return NULL;
}
arrivalChanged();
}
-
int index = _routeMgr->currentIndex(),
count = _routeMgr->numWaypts();
if ((index < 0) || (index >= count)) {
+ _currentWaypt=NULL;
+ _prevWaypt=NULL;
SG_LOG(SG_INSTR, SG_ALERT, "GPS: malformed route, index=" << index);
return;
}
void GPS::wp1Changed()
{
+ if (!_currentWaypt)
+ return;
if (_mode == "leg") {
_wayptController.reset(WayptController::createForWaypt(this, _currentWaypt));
} else if (_mode == "obs") {
const char* GPS::getWP0Ident() const
{
- if (!_dataValid || (_mode != "leg")) {
+ if (!_dataValid || (_mode != "leg") || (!_prevWaypt)) {
return "";
}
const char* GPS::getWP1Ident() const
{
- if (!_dataValid) {
+ if ((!_dataValid)||(!_currentWaypt)) {
return "";
}