Added a clear of allocated Records and the cache's in flt::Registry to
prevent memory leaks and unneccesary references to model models remaining beyond the scope of the loader.
This commit is contained in:
@@ -499,25 +499,3 @@ void LocalVertexPoolRecord::postReadInit()
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Make this instance the current one.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void LocalVertexPoolRecord::makeCurrent()
|
||||
{
|
||||
_current = this;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Return the current instance.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
LocalVertexPoolRecord *LocalVertexPoolRecord::getCurrent()
|
||||
{
|
||||
return _current;
|
||||
}
|
||||
|
||||
@@ -69,9 +69,6 @@ public:
|
||||
|
||||
virtual size_t sizeofData() const { return sizeof ( SLocalVertexPool ); }
|
||||
|
||||
void makeCurrent();
|
||||
static LocalVertexPoolRecord * getCurrent();
|
||||
|
||||
protected:
|
||||
|
||||
class Offset
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#include "ReaderWriterFLT.h"
|
||||
#include "FltFile.h"
|
||||
#include "Registry.h"
|
||||
|
||||
#include <osg/Object>
|
||||
#include <osg/Node>
|
||||
@@ -27,7 +28,7 @@ osgDB::ReaderWriter::ReadResult ReaderWriterFLT::readNode(const std::string& fil
|
||||
return ReadResult::FILE_NOT_HANDLED;
|
||||
|
||||
osg::ref_ptr<FltFile> read = new FltFile;
|
||||
|
||||
|
||||
if (options)
|
||||
{
|
||||
read->setUseTextureAlphaForTransparancyBinning(options->getOptionString().find("noTextureAlphaForTransparancyBinning")==std::string::npos);
|
||||
@@ -35,6 +36,9 @@ osgDB::ReaderWriter::ReadResult ReaderWriterFLT::readNode(const std::string& fil
|
||||
}
|
||||
|
||||
osg::Node* node = read->readNode(fileName);
|
||||
|
||||
flt::Registry::instance()->clearObjectCache();
|
||||
|
||||
if (node) return node;
|
||||
else return ReadResult::FILE_NOT_HANDLED;
|
||||
}
|
||||
|
||||
@@ -23,16 +23,24 @@ using namespace flt;
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
int Record::s_numAllocatedRecords=0;
|
||||
|
||||
Record::Record()
|
||||
{
|
||||
_pData = NULL;
|
||||
_pParent = NULL;
|
||||
_pFltFile = NULL;
|
||||
|
||||
++s_numAllocatedRecords;
|
||||
|
||||
flt::Registry::instance()->addRecordForFutureDelete(this);
|
||||
}
|
||||
|
||||
|
||||
Record::~Record()
|
||||
{
|
||||
--s_numAllocatedRecords;
|
||||
|
||||
if (_pData) ::free(_pData);
|
||||
}
|
||||
|
||||
|
||||
@@ -33,6 +33,9 @@ class Record : public osg::Referenced
|
||||
{
|
||||
public:
|
||||
|
||||
// used for debugging the number of records created and deleted.
|
||||
static int s_numAllocatedRecords;
|
||||
|
||||
Record();
|
||||
|
||||
virtual Record* clone() const = 0;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
|
||||
;
|
||||
#include <osg/Node>
|
||||
#include <osg/Group>
|
||||
#include <osg/Notify>
|
||||
@@ -13,7 +13,6 @@
|
||||
|
||||
using namespace flt;
|
||||
|
||||
// static
|
||||
Registry* Registry::instance()
|
||||
{
|
||||
static Registry s_nodeFactory;
|
||||
@@ -44,6 +43,7 @@ Record* Registry::getPrototype(const int opcode)
|
||||
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
@@ -80,3 +80,10 @@ FltFile* Registry::getFltFile(const std::string& name)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void Registry::clearObjectCache()
|
||||
{
|
||||
_textureMap.clear();
|
||||
_fltFileMap.clear();
|
||||
|
||||
_recordForFutureDeleteList.clear();
|
||||
}
|
||||
|
||||
@@ -52,12 +52,18 @@ class Registry
|
||||
|
||||
void addFltFile(const std::string& name, FltFile* file);
|
||||
FltFile* getFltFile(const std::string& name);
|
||||
|
||||
void clearObjectCache();
|
||||
|
||||
void addRecordForFutureDelete(Record* rec) { _recordForFutureDeleteList.push_back(rec); }
|
||||
|
||||
private:
|
||||
|
||||
typedef std::map<int, osg::ref_ptr<Record> > RecordProtoMap;
|
||||
typedef std::map<std::string, osg::ref_ptr<osg::StateSet> > TextureMap;
|
||||
typedef std::map<std::string, osg::ref_ptr<FltFile> > FltFileMap;
|
||||
|
||||
typedef std::vector<osg::ref_ptr<Record> > RecordsForFutureDeleteList;
|
||||
|
||||
/** constructor is private, as its a singleton, preventing
|
||||
construction other than via the instance() method and
|
||||
@@ -67,6 +73,8 @@ class Registry
|
||||
RecordProtoMap _recordProtoMap;
|
||||
TextureMap _textureMap;
|
||||
FltFileMap _fltFileMap;
|
||||
|
||||
RecordsForFutureDeleteList _recordForFutureDeleteList;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -90,6 +90,7 @@ ConvertFromFLT::ConvertFromFLT() :
|
||||
_unitScale = 1.0;
|
||||
_useTextureAlphaForTranspancyBinning = true;
|
||||
_bHdrRgbMode = false;
|
||||
_currentLocalVertexPool = 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -1891,7 +1892,7 @@ int ConvertFromFLT::addMeshPrimitives ( osg::Group &parent, GeoSetBuilder *, Mes
|
||||
int ConvertFromFLT::visitLocalVertexPool ( GeoSetBuilder *, LocalVertexPoolRecord *rec )
|
||||
{
|
||||
// Make the given instance the current one.
|
||||
rec->makeCurrent();
|
||||
_currentLocalVertexPool = rec;
|
||||
|
||||
// We didn't add any vertices.
|
||||
return 0;
|
||||
@@ -1900,11 +1901,22 @@ int ConvertFromFLT::visitLocalVertexPool ( GeoSetBuilder *, LocalVertexPoolRecor
|
||||
|
||||
void ConvertFromFLT::visitMeshPrimitive ( osg::Group &parent, MeshPrimitiveRecord *mesh )
|
||||
{
|
||||
assert ( mesh );
|
||||
if ( !mesh )
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<"Warning:ConvertFromFLT::visitMeshPrimitive () mesh is 0, unable to process."<<std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
osg::Geode *geode = new osg::Geode();
|
||||
osg::Geometry *geometry = new osg::Geometry();
|
||||
LocalVertexPoolRecord *pool = LocalVertexPoolRecord::getCurrent();
|
||||
LocalVertexPoolRecord *pool = _currentLocalVertexPool;
|
||||
|
||||
if (!pool)
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<"Warning:ConvertFromFLT::visitMeshPrimitive () pool is 0, unable to process."<<std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
assert ( pool );
|
||||
|
||||
// Set the correct primitive type.
|
||||
|
||||
@@ -189,16 +189,18 @@ class ConvertFromFLT
|
||||
typedef std::map<int,Record*> VertexPaletteOffsetMap;
|
||||
VertexPaletteOffsetMap _VertexPaletteOffsetMap;
|
||||
|
||||
int _diOpenFlightVersion;
|
||||
int _diCurrentOffset;
|
||||
unsigned short _wObjTransparency;
|
||||
int _nSubfaceLevel;
|
||||
double _unitScale;
|
||||
bool _bHdrRgbMode;
|
||||
osg::Vec4 _faceColor;
|
||||
bool _useTextureAlphaForTranspancyBinning;
|
||||
int _diOpenFlightVersion;
|
||||
int _diCurrentOffset;
|
||||
unsigned short _wObjTransparency;
|
||||
int _nSubfaceLevel;
|
||||
double _unitScale;
|
||||
bool _bHdrRgbMode;
|
||||
osg::Vec4 _faceColor;
|
||||
bool _useTextureAlphaForTranspancyBinning;
|
||||
|
||||
osg::Group* _osgParent;
|
||||
osg::Group* _osgParent;
|
||||
|
||||
LocalVertexPoolRecord* _currentLocalVertexPool;
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user