From Per Fahlberg, "I've fixed the dae plugin so it is only using one instance of the DAE.

The crashes seen earlier are gone, it is now possible to read multiple
.dae files and converting both to and from .dae files."
This commit is contained in:
Robert Osfield
2006-09-15 13:11:00 +00:00
parent fa76f7e973
commit fa791e99b8
5 changed files with 32 additions and 28 deletions

View File

@@ -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<osg::Node*>(&node)->accept( daeWriter );

View File

@@ -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;
}

View File

@@ -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 );

View File

@@ -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 )

View File

@@ -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 );