Hi Roger,
Thanks for your efforts! This helped me come up with a possible
solution. What do you think about the modifications to the attached
ReaderWriterDAE.cpp? I create the DAE instance when it's first needed
instead of in the constructor. I had to use const_cast to do this, maybe
not the nicest code, but I couldn't see any alternative. Anyway, it
seems to work fine and I'd appreciate it if you verified this. If you or
anyone else can't see any problem with the solution I will submit the
modifications to Robert.
/Andreas
Roger James wrote:
On further investigation it looks like the constructor of the global
osgDB::RegisterReaderWriterProxy<ReaderWriterDAE> g_readerWriter_DAE_Proxy;
in ReaderWriterDAE.cpp
is being called before the constructor of the static
daeStringTable daeStringRef::_stringTable;
in daestringref.cpp
From memory the only way you force ordering of global initialisation in C++
it to put them in the same file. But I tried this and it did not work :-(.
Roger
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:osg-users-
[EMAIL PROTECTED] On Behalf Of Roger James
Sent: 27 September 2006 15:49
To: 'osg users'
Subject: RE: [osg-users] Collada plugin not working
Anders,
I think I am seeing the same behaviour as you.
My environment is MSVC7.1.
The plugin dll crashes during its initialisation phase when the global
reader writer proxy object is created by the runtime.
_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/
--
________________________________________________________________________
Andreas Ekstrand
Remograph
Rekrytgatan 10
SE-582 14 Linköping
SWEDEN
Website: http://www.remograph.com
E-mail: [EMAIL PROTECTED]
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This application is open source and may be redistributed and/or modified
* freely and without restriction, both in commericial and non commericial
* applications, as long as this copyright notice is maintained.
*
* This application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
*/
#include <sstream>
#include <osg/Notify>
#include <osgDB/ReaderWriter>
#include <osgDB/FileNameUtils>
#include <osgDB/Registry>
#include "daeReader.h"
#include "daeWriter.h"
#define EXTENSION_NAME "dae"
///////////////////////////////////////////////////////////////////////////
// OSG reader/writer plugin for the COLLADA 1.4.x ".dae" format.
// See http://collada.org/ and http://khronos.org/collada/
class ReaderWriterDAE : public osgDB::ReaderWriter
{
public:
ReaderWriterDAE() : dae_(NULL)
{
}
~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
{
return osgDB::equalCaseInsensitive( extension, EXTENSION_NAME );
}
ReadResult readNode(const std::string&, const Options*) const;
WriteResult writeNode(const osg::Node&, const std::string&, const Options*)
const;
private:
DAE *dae_;
};
///////////////////////////////////////////////////////////////////////////
osgDB::ReaderWriter::ReadResult
ReaderWriterDAE::readNode(const std::string& fname,
const osgDB::ReaderWriter::Options* options) const
{
std::string ext( osgDB::getLowerCaseFileExtension(fname) );
if( ! acceptsExtension(ext) ) return ReadResult::FILE_NOT_HANDLED;
std::string fileName( osgDB::findDataFile( fname, options ) );
if( fileName.empty() ) return ReadResult::FILE_NOT_FOUND;
osg::notify(osg::INFO) << "ReaderWriterDAE( \"" << fileName << "\" )" <<
std::endl;
if (dae_ == NULL)
const_cast<ReaderWriterDAE *>(this)->dae_ = new DAE();
osgdae::daeReader daeReader(dae_);
std::string fileURI( osgDB::convertFileNameToUnixStyle(fileName) );
if ( ! daeReader.convert( fileURI ) )
{
osg::notify( osg::WARN ) << "Load failed in COLLADA DOM conversion" <<
std::endl;
return ReadResult::ERROR_IN_READING_FILE;
}
osg::Node* rootNode( daeReader.getRootNode() );
return rootNode;
}
///////////////////////////////////////////////////////////////////////////
osgDB::ReaderWriter::WriteResult
ReaderWriterDAE::writeNode( const osg::Node& node,
const std::string& fname, const osgDB::ReaderWriter::Options* options )
const
{
std::string ext( osgDB::getLowerCaseFileExtension(fname) );
if( ! acceptsExtension(ext) ) return WriteResult::FILE_NOT_HANDLED;
// Process options
bool usePolygon(false);
if( options )
{
std::istringstream iss( options->getOptionString() );
std::string opt;
while( std::getline( iss, opt, ',' ) )
{
if( opt == "polygon") usePolygon = true;
else
{
osg::notify(osg::WARN)
<< "\n" "COLLADA dae plugin: unrecognized option \"" << opt <<
"\"\n"
<< "comma-delimited options:\n"
<< "\tpolygon = use polygons instead of polylists for element\n"
<< "example: osgviewer -O polygon bar.dae" "\n"
<< std::endl;
}
}
}
if (dae_ == NULL)
const_cast<ReaderWriterDAE *>(this)->dae_ = new DAE();
osgdae::daeWriter daeWriter(dae_, fname, usePolygon );
daeWriter.setRootNode( node );
const_cast<osg::Node*>(&node)->accept( daeWriter );
osgDB::ReaderWriter::WriteResult retVal( WriteResult::ERROR_IN_WRITING_FILE
);
if ( daeWriter.isSuccess() )
{
if ( daeWriter.writeFile() )
{
retVal = WriteResult::FILE_SAVED;
}
}
return retVal;
}
///////////////////////////////////////////////////////////////////////////
// Add ourself to the Registry to instantiate the reader/writer.
osgDB::RegisterReaderWriterProxy<ReaderWriterDAE> g_readerWriter_DAE_Proxy;
// vim: set sw=4 ts=8 et ic ai:
_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/