From c542be533066f24cebd6ab689893e9f1fd66a319 Mon Sep 17 00:00:00 2001 From: ehofman Date: Wed, 8 Sep 2004 14:02:25 +0000 Subject: [PATCH] Make sure the pointer is not being used after deletion, and tie the elapsed time to the particular class instance. --- src/AIModel/AIBallistic.cxx | 9 ++++++++- src/AIModel/AIBallistic.hxx | 18 ++++++++++-------- src/AIModel/AIManager.cxx | 2 +- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/AIModel/AIBallistic.cxx b/src/AIModel/AIBallistic.cxx index ddac65cdf..94760bb77 100644 --- a/src/AIModel/AIBallistic.cxx +++ b/src/AIModel/AIBallistic.cxx @@ -51,7 +51,9 @@ bool FGAIBallistic::init() { void FGAIBallistic::bind() { // FGAIBase::bind(); - props->tie("sim/time/elapsed-sec", SGRawValuePointer(&(this->life_timer))); + props->tie("sim/time/elapsed-sec", + SGRawValueMethods(*this, + &FGAIBallistic::_getTime)); } void FGAIBallistic::unbind() { @@ -163,3 +165,8 @@ void FGAIBallistic::Run(double dt) { if (altitude < -1000.0) setDie(true); } + +double FGAIBallistic::_getTime() const { + return life_timer; +} + diff --git a/src/AIModel/AIBallistic.hxx b/src/AIModel/AIBallistic.hxx index 958cf952a..8a230b3c7 100644 --- a/src/AIModel/AIBallistic.hxx +++ b/src/AIModel/AIBallistic.hxx @@ -42,9 +42,11 @@ public: void setDragArea( double a ); void setLife( double seconds ); void setBuoyancy( double fpss ); - void setWind_from_east( double fps ); - void setWind_from_north( double fps ); - void setWind( bool val ); + void setWind_from_east( double fps ); + void setWind_from_north( double fps ); + void setWind( bool val ); + + double _getTime() const; private: @@ -54,11 +56,11 @@ private: bool aero_stabilized; // if true, object will point where it's going double drag_area; // equivalent drag area in ft2 double life_timer; // seconds - double gravity; // fps2 - double buoyancy; // fps2 - double wind_from_east; // fps - double wind_from_north; // fps - bool wind; // if true, local wind will be applied to object + double gravity; // fps2 + double buoyancy; // fps2 + double wind_from_east; // fps + double wind_from_north; // fps + bool wind; // if true, local wind will be applied to object void Run(double dt); }; diff --git a/src/AIModel/AIManager.cxx b/src/AIModel/AIManager.cxx index 97769619c..a4a713a7d 100644 --- a/src/AIModel/AIManager.cxx +++ b/src/AIModel/AIManager.cxx @@ -95,9 +95,9 @@ void FGAIManager::update(double dt) { ai_list_itr = ai_list.begin(); while(ai_list_itr != ai_list.end()) { if ((*ai_list_itr)->getDie()) { - delete (*ai_list_itr); --numObjects[(*ai_list_itr)->getType()]; --numObjects[0]; + delete (*ai_list_itr); if ( ai_list_itr == ai_list.begin() ) { ai_list.erase(ai_list_itr); ai_list_itr = ai_list.begin(); -- 2.39.5