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:";
smgr->remove(name.str());
}
- delete fp;
+ if (fp)
+ delete fp;
fp = 0;
}
void
FGAIBase::removeModel()
{
+ if (!_model.valid())
+ return;
+
FGScenery* pSceneryManager = globals->get_scenery();
if (pSceneryManager)
{
pitch*speed );
_fx->set_velocity( velocity );
}
- else if (_aimodel)
+ else if ((_aimodel)&&(fgGetBool("/sim/sound/aimodels/enabled",false)))
{
string fxpath = _aimodel->get_sound_path();
if (fxpath != "")
}
-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)
{
_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");
props->setBoolValue("/sim/controls/radar/", true);
+ // drop reference to sound effects now
+ _fx = 0;
}
double FGAIBase::UpdateRadar(FGAIManager* manager) {
{
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);
}