diff --git a/src/osgPlugins/dae/ReaderWriterDAE.cpp b/src/osgPlugins/dae/ReaderWriterDAE.cpp index fbb6bb663..2d210af5c 100644 --- a/src/osgPlugins/dae/ReaderWriterDAE.cpp +++ b/src/osgPlugins/dae/ReaderWriterDAE.cpp @@ -29,8 +29,20 @@ class ReaderWriterDAE : public osgDB::ReaderWriter { public: - ReaderWriterDAE() {} - + ReaderWriterDAE() + { + dae_ = new DAE(); + } + + ~ReaderWriterDAE() + { + if(dae_ != NULL){ + delete dae_; + DAE::cleanup(); + dae_ = NULL; + } + } + const char* className() const { return "COLLADA 1.4.x DAE reader/writer"; } bool acceptsExtension(const std::string& extension) const @@ -41,6 +53,11 @@ public: ReadResult readNode(const std::string&, const Options*) const; WriteResult writeNode(const osg::Node&, const std::string&, const Options*) const; + +private: + + DAE *dae_; + }; /////////////////////////////////////////////////////////////////////////// @@ -57,7 +74,7 @@ ReaderWriterDAE::readNode(const std::string& fname, osg::notify(osg::INFO) << "ReaderWriterDAE( \"" << fileName << "\" )" << std::endl; - osgdae::daeReader daeReader; + osgdae::daeReader daeReader(dae_); std::string fileURI( osgDB::convertFileNameToUnixStyle(fileName) ); if ( ! daeReader.convert( fileURI ) ) { @@ -100,7 +117,7 @@ ReaderWriterDAE::writeNode( const osg::Node& node, } } - osgdae::daeWriter daeWriter( fname, usePolygon ); + osgdae::daeWriter daeWriter(dae_, fname, usePolygon ); daeWriter.setRootNode( node ); const_cast(&node)->accept( daeWriter ); diff --git a/src/osgPlugins/dae/daeReader.cpp b/src/osgPlugins/dae/daeReader.cpp index 9ae993447..0ea223c43 100644 --- a/src/osgPlugins/dae/daeReader.cpp +++ b/src/osgPlugins/dae/daeReader.cpp @@ -18,21 +18,17 @@ using namespace osgdae; -daeReader::daeReader() +daeReader::daeReader(DAE *dae_) : dae(dae_), + rootNode(NULL), + m_numlights(0), + currentEffect(NULL), + geometryMap(), + materialMap() { - dae = new DAE; - m_numlights = 0; - currentEffect = NULL; } daeReader::~daeReader() { - if ( dae ) - { - delete dae; - DAE::cleanup(); - dae = NULL; - } } bool daeReader::convert( const std::string &fileURI ) @@ -70,9 +66,6 @@ bool daeReader::convert( const std::string &fileURI ) } rootNode = processVisualScene( vs ); - delete dae; - DAE::cleanup(); - dae = NULL; return true; } diff --git a/src/osgPlugins/dae/daeReader.h b/src/osgPlugins/dae/daeReader.h index b5c9621cc..fe5bd7198 100644 --- a/src/osgPlugins/dae/daeReader.h +++ b/src/osgPlugins/dae/daeReader.h @@ -101,7 +101,7 @@ bool findInputSourceBySemantic( TInputArray& inputs, const char* semantic, daeEl */ class daeReader { public: - daeReader(); + daeReader(DAE *dae_); virtual ~daeReader(); bool convert( const std::string &fileURI ); diff --git a/src/osgPlugins/dae/daeWriter.cpp b/src/osgPlugins/dae/daeWriter.cpp index c5519de91..f3fc4bb1a 100644 --- a/src/osgPlugins/dae/daeWriter.cpp +++ b/src/osgPlugins/dae/daeWriter.cpp @@ -22,12 +22,12 @@ using namespace osgdae; -daeWriter::daeWriter( const std::string &fname,bool _usePolygons ) : osg::NodeVisitor( TRAVERSE_ALL_CHILDREN ), -usePolygons (_usePolygons) +daeWriter::daeWriter( DAE *dae_, const std::string &fname,bool _usePolygons ) : osg::NodeVisitor( TRAVERSE_ALL_CHILDREN ), + dae(dae_), + usePolygons (_usePolygons) { success = true; - dae = new DAE(); dae->setDatabase( NULL ); dae->setIOPlugin( NULL ); //create document @@ -58,12 +58,6 @@ usePolygons (_usePolygons) daeWriter::~daeWriter() { - if ( dae != NULL ) - { - delete dae; - DAE::cleanup(); - dae = 0; - } } void daeWriter::debugPrint( osg::Node &node ) diff --git a/src/osgPlugins/dae/daeWriter.h b/src/osgPlugins/dae/daeWriter.h index e873cbca3..d8752cfdf 100644 --- a/src/osgPlugins/dae/daeWriter.h +++ b/src/osgPlugins/dae/daeWriter.h @@ -74,7 +74,7 @@ protected: public: enum NodeType { NODE, GEODE, GROUP, LIGHT, CAMERA, MATRIX, POSATT, SWITCH, LOD }; - daeWriter( const std::string &fname, bool usePolygons=false ); + daeWriter( DAE *dae_, const std::string &fname, bool usePolygons=false ); virtual ~daeWriter(); void setRootNode( const osg::Node &node );