]> git.mxchange.org Git - flightgear.git/blobdiff - src/AIModel/AIBase.cxx
properly add librt when clock_gettime is used
[flightgear.git] / src / AIModel / AIBase.cxx
index 230837621f32712504766c46d63a61255cdd315b..07fc6c31a49c38f86883ec0ee03ffd0da94efb70 100644 (file)
@@ -145,7 +145,7 @@ FGAIBase::~FGAIBase() {
             model_removed->setStringValue(props->getPath());
     }
 
-    if (_refID != 0 && _refID !=  1) {
+    if (_fx && _refID != 0 && _refID !=  1) {
         SGSoundMgr *smgr = globals->get_soundmgr();
         stringstream name; 
         name <<  "aifx:";
@@ -153,7 +153,8 @@ FGAIBase::~FGAIBase() {
         smgr->remove(name.str());
     }
 
-    delete fp;
+    if (fp)
+        delete fp;
     fp = 0;
 }
 
@@ -163,6 +164,9 @@ FGAIBase::~FGAIBase() {
 void
 FGAIBase::removeModel()
 {
+    if (!_model.valid())
+        return;
+
     FGScenery* pSceneryManager = globals->get_scenery();
     if (pSceneryManager)
     {
@@ -287,8 +291,14 @@ void FGAIBase::Transform() {
 
 }
 
-bool FGAIBase::init(bool search_in_AI_path) {
-    
+bool FGAIBase::init(bool search_in_AI_path)
+{
+    if (_model.valid())
+    {
+        SG_LOG(SG_AI, SG_ALERT, "AIBase: Cannot initialize a model multiple times! " << model_path);
+        return false;
+    }
+
     string f;
     if(search_in_AI_path)
     {
@@ -317,12 +327,6 @@ bool FGAIBase::init(bool search_in_AI_path) {
     _aimodel = new FGAIModelData(props);
     osg::Node * mdl = SGModelLib::loadDeferredModel(f, props, _aimodel);
 
-    if (_model.valid())
-    {
-        // reinit, dump the old model
-        removeModel();
-    }
-
     _model = new osg::LOD;
     _model->setName("AI-model range animation node");
 
@@ -921,10 +925,7 @@ void FGAIModelData::modelLoaded(const string& path, SGPropertyNode *prop, osg::N
 {
     const char* fxpath = prop->getStringValue("sound/path");
     if (fxpath) {
-        string sound_path = string(fxpath);
-        if (sound_path != "") {
-            _path = "/AI/"+sound_path;
-        }
+        _path = string(fxpath);
     }
     _nasal->modelLoaded(path, prop, n);
 }