diff --git a/src/Autopilot/route_mgr.cxx b/src/Autopilot/route_mgr.cxx index c0f8f2631..1530497e8 100644 --- a/src/Autopilot/route_mgr.cxx +++ b/src/Autopilot/route_mgr.cxx @@ -345,7 +345,7 @@ flightgear::WayptRef FGRouteMgr::removeWayptAtIndex(int aIndex) { 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())) { @@ -1027,7 +1027,7 @@ void FGRouteMgr::jumpToIndex(int index) void FGRouteMgr::currentWaypointChanged() { - Waypt* cur = (_currentIndexgetChild("id")->setStringValue(cur ? cur->ident() : ""); @@ -1050,6 +1050,8 @@ int FGRouteMgr::findWayptIndex(const SGGeod& aPos) const Waypt* FGRouteMgr::currentWaypt() const { + if ((_currentIndex < 0) || (_currentIndex >= numWaypts())) + return NULL; return wayptAtIndex(_currentIndex); } @@ -1064,7 +1066,7 @@ Waypt* FGRouteMgr::previousWaypt() const Waypt* FGRouteMgr::nextWaypt() const { - if ((_currentIndex + 1) >= numWaypts()) { + if ((_currentIndex < 0) || ((_currentIndex + 1) >= numWaypts())) { return NULL; } @@ -1353,4 +1355,3 @@ void FGRouteMgr::setDestinationICAO(const char* aIdent) arrivalChanged(); } - diff --git a/src/Instrumentation/gps.cxx b/src/Instrumentation/gps.cxx index 1add1b97f..7e4b2b398 100644 --- a/src/Instrumentation/gps.cxx +++ b/src/Instrumentation/gps.cxx @@ -697,6 +697,8 @@ void GPS::routeManagerSequenced() 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; } @@ -971,6 +973,8 @@ void GPS::driveAutopilot() void GPS::wp1Changed() { + if (!_currentWaypt) + return; if (_mode == "leg") { _wayptController.reset(WayptController::createForWaypt(this, _currentWaypt)); } else if (_mode == "obs") { @@ -1082,7 +1086,7 @@ double GPS::getCDIDeflection() const const char* GPS::getWP0Ident() const { - if (!_dataValid || (_mode != "leg")) { + if (!_dataValid || (_mode != "leg") || (!_prevWaypt)) { return ""; } @@ -1096,7 +1100,7 @@ const char* GPS::getWP0Name() const const char* GPS::getWP1Ident() const { - if (!_dataValid) { + if ((!_dataValid)||(!_currentWaypt)) { return ""; } diff --git a/src/Instrumentation/navradio.cxx b/src/Instrumentation/navradio.cxx index 2aac4b26d..143951694 100644 --- a/src/Instrumentation/navradio.cxx +++ b/src/Instrumentation/navradio.cxx @@ -92,12 +92,19 @@ SGPropertyNode_ptr createServiceableProp(SGPropertyNode* aParent, const char* aN // Constructor FGNavRadio::FGNavRadio(SGPropertyNode *node) : + term_tbl(NULL), + low_tbl(NULL), + high_tbl(NULL), lon_node(fgGetNode("/position/longitude-deg", true)), lat_node(fgGetNode("/position/latitude-deg", true)), alt_node(fgGetNode("/position/altitude-ft", true)), + _operable(false), play_count(0), last_time(0), target_radial(0.0), + effective_range(0.0), + target_gs(0.0), + twist(0.0), horiz_vel(0.0), last_x(0.0), last_loc_dist(0.0), @@ -107,6 +114,16 @@ FGNavRadio::FGNavRadio(SGPropertyNode *node) : _name(node->getStringValue("name", "nav")), _num(node->getIntValue("number", 0)), _time_before_search_sec(-1.0), + _gsCart(SGVec3d::zeros()), + _gsAxis(SGVec3d::zeros()), + _gsVertical(SGVec3d::zeros()), + _dmeInRange(false), + _toFlag(false), + _fromFlag(false), + _cdiDeflection(0.0), + _cdiCrossTrackErrorM(0.0), + _gsNeedleDeflection(0.0), + _gsNeedleDeflectionNorm(0.0), _sgr(NULL) { SGPath path( globals->get_fg_root() ); @@ -120,8 +137,7 @@ FGNavRadio::FGNavRadio(SGPropertyNode *node) : term_tbl = new SGInterpTable( term.str() ); low_tbl = new SGInterpTable( low.str() ); high_tbl = new SGInterpTable( high.str() ); - - + string branch("/instrumentation/" + _name); _radio_node = fgGetNode(branch.c_str(), _num, true); } diff --git a/src/Instrumentation/navradio.hxx b/src/Instrumentation/navradio.hxx index f272f6700..a8451a649 100644 --- a/src/Instrumentation/navradio.hxx +++ b/src/Instrumentation/navradio.hxx @@ -137,8 +137,6 @@ class FGNavRadio : public SGSubsystem, public SGPropertyChangeListener string dme_fx_name; double target_radial; - SGTimeStamp prev_time; - SGTimeStamp curr_time; double effective_range; double target_gs; double twist; diff --git a/src/Instrumentation/rnav_waypt_controller.cxx b/src/Instrumentation/rnav_waypt_controller.cxx index 977452e18..09ac2b812 100644 --- a/src/Instrumentation/rnav_waypt_controller.cxx +++ b/src/Instrumentation/rnav_waypt_controller.cxx @@ -69,8 +69,8 @@ bool geocRadialIntersection(const SGGeoc& a, double r1, const SGGeoc& b, double double crs12 = SGGeodesy::courseRad(a, b), crs21 = SGGeodesy::courseRad(b, a); - double degCrs12 = crs12 * SG_RADIANS_TO_DEGREES; - double degCrs21 = crs21 * SG_RADIANS_TO_DEGREES; + //double degCrs12 = crs12 * SG_RADIANS_TO_DEGREES; + //double degCrs21 = crs21 * SG_RADIANS_TO_DEGREES; /* if (sin(diffLon) < 0.0) { @@ -157,7 +157,9 @@ class BasicWayptCtl : public WayptController { public: BasicWayptCtl(RNAV* aRNAV, const WayptRef& aWpt) : - WayptController(aRNAV, aWpt) + WayptController(aRNAV, aWpt), + _distanceM(0.0), + _courseDev(0.0) { if (aWpt->flag(WPT_DYNAMIC)) { throw sg_exception("BasicWayptCtrl doesn't work with dynamic waypoints"); @@ -226,7 +228,10 @@ class RunwayCtl : public WayptController { public: RunwayCtl(RNAV* aRNAV, const WayptRef& aWpt) : - WayptController(aRNAV, aWpt) + WayptController(aRNAV, aWpt), + _runway(NULL), + _distanceM(0.0), + _courseDev(0.0) { } @@ -365,8 +370,8 @@ class InterceptCtl : public WayptController { public: InterceptCtl(RNAV* aRNAV, const WayptRef& aWpt) : - WayptController(aRNAV, aWpt) - + WayptController(aRNAV, aWpt), + _trueRadial(0.0) { if (_waypt->type() != "radialIntercept") { throw sg_exception("invalid waypoint type", "InterceptCtl ctor"); @@ -412,8 +417,9 @@ class DMEInterceptCtl : public WayptController { public: DMEInterceptCtl(RNAV* aRNAV, const WayptRef& aWpt) : - WayptController(aRNAV, aWpt) - + WayptController(aRNAV, aWpt), + _dme(NULL), + _distanceNm(0.0) { if (_waypt->type() != "dmeIntercept") { throw sg_exception("invalid waypoint type", "DMEInterceptCtl ctor"); @@ -546,7 +552,9 @@ private: DirectToController::DirectToController(RNAV* aRNAV, const WayptRef& aWpt, const SGGeod& aOrigin) : WayptController(aRNAV, aWpt), - _origin(aOrigin) + _origin(aOrigin), + _distanceM(0.0), + _courseDev(0.0) { } @@ -600,7 +608,9 @@ SGGeod DirectToController::position() const /////////////////////////////////////////////////////////////////////////////// OBSController::OBSController(RNAV* aRNAV, const WayptRef& aWpt) : - WayptController(aRNAV, aWpt) + WayptController(aRNAV, aWpt), + _distanceM(0.0), + _courseDev(0.0) { } diff --git a/src/Instrumentation/rnav_waypt_controller.hxx b/src/Instrumentation/rnav_waypt_controller.hxx index 4d99c8af7..b5c4b19e1 100644 --- a/src/Instrumentation/rnav_waypt_controller.hxx +++ b/src/Instrumentation/rnav_waypt_controller.hxx @@ -129,6 +129,7 @@ public: protected: WayptController(RNAV* aRNAV, const WayptRef& aWpt) : _waypt(aWpt), + _targetTrack(0), _rnav(aRNAV), _isDone(false) { }