1
0
Fork 0

Fix a FlightPlan lifetime issue.

Route-manager was explicitly deleting its FP, which was incorrect.
Switch to correct use of SGSharedPtr to refer to flight plans.

Thanks to Roland Haeder for catching this.
This commit is contained in:
James Turner 2013-05-26 22:11:11 +01:00
parent 1ad9756a4b
commit 16d1c47664
4 changed files with 16 additions and 11 deletions

View file

@ -401,12 +401,12 @@ bool FGRouteMgr::loadRoute(const SGPath& p)
return true; return true;
} }
FlightPlan* FGRouteMgr::flightPlan() const FlightPlanRef FGRouteMgr::flightPlan() const
{ {
return _plan; return _plan;
} }
void FGRouteMgr::setFlightPlan(FlightPlan* plan) void FGRouteMgr::setFlightPlan(const FlightPlanRef& plan)
{ {
if (plan == _plan) { if (plan == _plan) {
return; return;
@ -414,7 +414,6 @@ void FGRouteMgr::setFlightPlan(FlightPlan* plan)
if (_plan) { if (_plan) {
_plan->removeDelegate(this); _plan->removeDelegate(this);
delete _plan;
active->setBoolValue(false); active->setBoolValue(false);
} }

View file

@ -55,8 +55,8 @@ public:
int currentIndex() const; int currentIndex() const;
void setFlightPlan(flightgear::FlightPlan* plan); void setFlightPlan(const flightgear::FlightPlanRef& plan);
flightgear::FlightPlan* flightPlan() const; flightgear::FlightPlanRef flightPlan() const;
void clearRoute(); void clearRoute();
@ -104,7 +104,7 @@ private:
bool commandDefineUserWaypoint(const SGPropertyNode* arg); bool commandDefineUserWaypoint(const SGPropertyNode* arg);
bool commandDeleteUserWaypoint(const SGPropertyNode* arg); bool commandDeleteUserWaypoint(const SGPropertyNode* arg);
flightgear::FlightPlan* _plan; flightgear::FlightPlanRef _plan;
time_t _takeoffTime; time_t _takeoffTime;
time_t _touchdownTime; time_t _touchdownTime;

View file

@ -91,6 +91,11 @@ FlightPlan::~FlightPlan()
delete cur; delete cur;
} }
} }
// delete legs
BOOST_FOREACH(Leg* l, _legs) {
delete l;
}
} }
FlightPlan* FlightPlan::clone(const string& newIdent) const FlightPlan* FlightPlan::clone(const string& newIdent) const
@ -1193,18 +1198,16 @@ FlightPlan::Delegate::Delegate() :
_deleteWithPlan(false), _deleteWithPlan(false),
_inner(NULL) _inner(NULL)
{ {
} }
FlightPlan::Delegate::~Delegate() FlightPlan::Delegate::~Delegate()
{ {
} }
void FlightPlan::Delegate::removeInner(Delegate* d) void FlightPlan::Delegate::removeInner(Delegate* d)
{ {
if (!_inner) { if (!_inner) {
return; throw sg_exception("FlightPlan delegate not found");
} }
if (_inner == d) { if (_inner == d) {

View file

@ -31,6 +31,9 @@ namespace flightgear
{ {
class Transition; class Transition;
class FlightPlan;
typedef SGSharedPtr<FlightPlan> FlightPlanRef;
class FlightPlan : public RouteBase class FlightPlan : public RouteBase
{ {