]> git.mxchange.org Git - flightgear.git/blobdiff - src/AIModel/AIBase.cxx
fix a segmentation fault situation that is exposed at least on IRIX (but not Linux).
[flightgear.git] / src / AIModel / AIBase.cxx
index e69602253bc19755fbc01d34d58fcf68c1661410..057f3bc84791f022a6502c3a0b232ebe40074ad5 100644 (file)
 #include "AIBase.hxx"
 #include "AIManager.hxx"
 
-FGAIBase::FGAIBase() {
+
+const double FGAIBase::rho = 0.023780;  // sea level air density slugs/ft3
+const double FGAIBase::lbs_to_slugs = 0.031080950172;   //conversion factor
+
+
+FGAIBase::FGAIBase()
+ :  fp( NULL ),
+    model( NULL ),
+    props( NULL ),
+    manager( NULL )
+{
     _type_str = "model";
     tgt_roll = roll = tgt_pitch = tgt_yaw = tgt_vs = vs = pitch = 0.0;
     bearing = elevation = range = rdot = 0.0;
@@ -53,12 +63,9 @@ FGAIBase::FGAIBase() {
     no_roll = true;
     life = 900;
     model_path = "";
-    model = 0;
     _otype = otNull;
     index = 0;
-    fp = (FGAIFlightPlan*)0;
     delete_me = false;
-    manager = NULL;
 }
 
 FGAIBase::~FGAIBase() {
@@ -67,6 +74,7 @@ FGAIBase::~FGAIBase() {
     SGPropertyNode *root = globals->get_props()->getNode("ai/models", true);
     root->removeChild(_type_str.c_str(), index);
     if (fp) delete fp;
+    fp = NULL;
 }
 
 void FGAIBase::update(double dt) {
@@ -124,7 +132,8 @@ bool FGAIBase::isa( object_type otype ) {
 
 
 void FGAIBase::bind() {
-   props->tie("id", SGRawValuePointer<int>(&id));
+   props->tie("id", SGRawValueMethods<FGAIBase,int>(*this,
+                                         &FGAIBase::_getID));
    props->tie("velocities/true-airspeed-kt",  SGRawValuePointer<double>(&speed));
    props->tie("velocities/vertical-speed-fps",
                SGRawValueMethods<FGAIBase,double>(*this,
@@ -313,3 +322,6 @@ bool FGAIBase::_isNight() {
     return (fgGetFloat("/sim/time/sun-angle-rad") > 1.57);
 }
 
+int FGAIBase::_getID() const {
+    return (int)(this);
+}