From bfb0619f76e68880a167c986d993db182368e45b Mon Sep 17 00:00:00 2001 From: ThorstenB Date: Fri, 9 Dec 2011 17:03:14 +0100 Subject: [PATCH] Fix memory leak with FGAIModelData. Be lazy and use ref pointers - to remove memory automatically. --- src/AIModel/AIBase.cxx | 5 +++-- src/AIModel/AIBase.hxx | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/AIModel/AIBase.cxx b/src/AIModel/AIBase.cxx index 230837621..e307a1d83 100644 --- a/src/AIModel/AIBase.cxx +++ b/src/AIModel/AIBase.cxx @@ -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; } diff --git a/src/AIModel/AIBase.hxx b/src/AIModel/AIBase.hxx index f09a96e00..b4815c41a 100644 --- a/src/AIModel/AIBase.hxx +++ b/src/AIModel/AIBase.hxx @@ -230,7 +230,7 @@ private: bool _initialized; osg::ref_ptr _model; //The 3D model LOD object - FGAIModelData* _aimodel; + osg::ref_ptr _aimodel; string _fxpath; SGSharedPtr _fx;