Avoid exceptions in route manager module.
Avoid segfaults in gps when route manager doesn't throw exceptions. Minor fix when removing waypoints by negative index.
This commit is contained in:
parent
ebbd5bfd05
commit
138449f4bd
2 changed files with 11 additions and 6 deletions
|
@ -345,7 +345,7 @@ flightgear::WayptRef FGRouteMgr::removeWayptAtIndex(int aIndex)
|
||||||
{
|
{
|
||||||
int index = aIndex;
|
int index = aIndex;
|
||||||
if (aIndex < 0) { // negative indices count the the end
|
if (aIndex < 0) { // negative indices count the the end
|
||||||
index = _route.size() - index;
|
index = _route.size() + index;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((index < 0) || (index >= numWaypts())) {
|
if ((index < 0) || (index >= numWaypts())) {
|
||||||
|
@ -1027,7 +1027,7 @@ void FGRouteMgr::jumpToIndex(int index)
|
||||||
|
|
||||||
void FGRouteMgr::currentWaypointChanged()
|
void FGRouteMgr::currentWaypointChanged()
|
||||||
{
|
{
|
||||||
Waypt* cur = (_currentIndex<numWaypts()) ? currentWaypt() : NULL;
|
Waypt* cur = currentWaypt();
|
||||||
Waypt* next = nextWaypt();
|
Waypt* next = nextWaypt();
|
||||||
|
|
||||||
wp0->getChild("id")->setStringValue(cur ? cur->ident() : "");
|
wp0->getChild("id")->setStringValue(cur ? cur->ident() : "");
|
||||||
|
@ -1050,6 +1050,8 @@ int FGRouteMgr::findWayptIndex(const SGGeod& aPos) const
|
||||||
|
|
||||||
Waypt* FGRouteMgr::currentWaypt() const
|
Waypt* FGRouteMgr::currentWaypt() const
|
||||||
{
|
{
|
||||||
|
if ((_currentIndex < 0) || (_currentIndex >= numWaypts()))
|
||||||
|
return NULL;
|
||||||
return wayptAtIndex(_currentIndex);
|
return wayptAtIndex(_currentIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1064,7 +1066,7 @@ Waypt* FGRouteMgr::previousWaypt() const
|
||||||
|
|
||||||
Waypt* FGRouteMgr::nextWaypt() const
|
Waypt* FGRouteMgr::nextWaypt() const
|
||||||
{
|
{
|
||||||
if ((_currentIndex + 1) >= numWaypts()) {
|
if ((_currentIndex < 0) || ((_currentIndex + 1) >= numWaypts())) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1353,4 +1355,3 @@ void FGRouteMgr::setDestinationICAO(const char* aIdent)
|
||||||
|
|
||||||
arrivalChanged();
|
arrivalChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -697,6 +697,8 @@ void GPS::routeManagerSequenced()
|
||||||
int index = _routeMgr->currentIndex(),
|
int index = _routeMgr->currentIndex(),
|
||||||
count = _routeMgr->numWaypts();
|
count = _routeMgr->numWaypts();
|
||||||
if ((index < 0) || (index >= count)) {
|
if ((index < 0) || (index >= count)) {
|
||||||
|
_currentWaypt=NULL;
|
||||||
|
_prevWaypt=NULL;
|
||||||
SG_LOG(SG_INSTR, SG_ALERT, "GPS: malformed route, index=" << index);
|
SG_LOG(SG_INSTR, SG_ALERT, "GPS: malformed route, index=" << index);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -971,6 +973,8 @@ void GPS::driveAutopilot()
|
||||||
|
|
||||||
void GPS::wp1Changed()
|
void GPS::wp1Changed()
|
||||||
{
|
{
|
||||||
|
if (!_currentWaypt)
|
||||||
|
return;
|
||||||
if (_mode == "leg") {
|
if (_mode == "leg") {
|
||||||
_wayptController.reset(WayptController::createForWaypt(this, _currentWaypt));
|
_wayptController.reset(WayptController::createForWaypt(this, _currentWaypt));
|
||||||
} else if (_mode == "obs") {
|
} else if (_mode == "obs") {
|
||||||
|
@ -1082,7 +1086,7 @@ double GPS::getCDIDeflection() const
|
||||||
|
|
||||||
const char* GPS::getWP0Ident() const
|
const char* GPS::getWP0Ident() const
|
||||||
{
|
{
|
||||||
if (!_dataValid || (_mode != "leg")) {
|
if (!_dataValid || (_mode != "leg") || (!_prevWaypt)) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1096,7 +1100,7 @@ const char* GPS::getWP0Name() const
|
||||||
|
|
||||||
const char* GPS::getWP1Ident() const
|
const char* GPS::getWP1Ident() const
|
||||||
{
|
{
|
||||||
if (!_dataValid) {
|
if ((!_dataValid)||(!_currentWaypt)) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue