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;
}
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);
}

View file

@ -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;

View file

@ -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) {

View file

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