diff --git a/src/Autopilot/route_mgr.cxx b/src/Autopilot/route_mgr.cxx index 3773c2e06..b1259f791 100644 --- a/src/Autopilot/route_mgr.cxx +++ b/src/Autopilot/route_mgr.cxx @@ -401,12 +401,12 @@ bool FGRouteMgr::loadRoute(const SGPath& p) return true; } -FlightPlan* FGRouteMgr::flightPlan() const +FlightPlanRef FGRouteMgr::flightPlan() const { return _plan; } -void FGRouteMgr::setFlightPlan(FlightPlan* plan) +void FGRouteMgr::setFlightPlan(const FlightPlanRef& plan) { if (plan == _plan) { return; @@ -414,7 +414,6 @@ void FGRouteMgr::setFlightPlan(FlightPlan* plan) if (_plan) { _plan->removeDelegate(this); - delete _plan; active->setBoolValue(false); } diff --git a/src/Autopilot/route_mgr.hxx b/src/Autopilot/route_mgr.hxx index 9fddc80f9..696d43d61 100644 --- a/src/Autopilot/route_mgr.hxx +++ b/src/Autopilot/route_mgr.hxx @@ -55,8 +55,8 @@ public: int currentIndex() const; - void setFlightPlan(flightgear::FlightPlan* plan); - flightgear::FlightPlan* flightPlan() const; + void setFlightPlan(const flightgear::FlightPlanRef& plan); + flightgear::FlightPlanRef flightPlan() const; void clearRoute(); @@ -104,7 +104,7 @@ private: bool commandDefineUserWaypoint(const SGPropertyNode* arg); bool commandDeleteUserWaypoint(const SGPropertyNode* arg); - flightgear::FlightPlan* _plan; + flightgear::FlightPlanRef _plan; time_t _takeoffTime; time_t _touchdownTime; diff --git a/src/Navaids/FlightPlan.cxx b/src/Navaids/FlightPlan.cxx index f19345ec3..2087d5cc1 100644 --- a/src/Navaids/FlightPlan.cxx +++ b/src/Navaids/FlightPlan.cxx @@ -91,6 +91,11 @@ FlightPlan::~FlightPlan() delete cur; } } + +// delete legs + BOOST_FOREACH(Leg* l, _legs) { + delete l; + } } FlightPlan* FlightPlan::clone(const string& newIdent) const @@ -1193,18 +1198,16 @@ FlightPlan::Delegate::Delegate() : _deleteWithPlan(false), _inner(NULL) { - } FlightPlan::Delegate::~Delegate() -{ - +{ } void FlightPlan::Delegate::removeInner(Delegate* d) { if (!_inner) { - return; + throw sg_exception("FlightPlan delegate not found"); } if (_inner == d) { diff --git a/src/Navaids/FlightPlan.hxx b/src/Navaids/FlightPlan.hxx index 836730e22..ceb5c9d19 100644 --- a/src/Navaids/FlightPlan.hxx +++ b/src/Navaids/FlightPlan.hxx @@ -31,7 +31,10 @@ namespace flightgear { class Transition; - +class FlightPlan; + +typedef SGSharedPtr FlightPlanRef; + class FlightPlan : public RouteBase { public: