From Mathias Fielder, "i found an issue with the serializer writing shared arrays. At OutputStream::writeArray(), if the currently latest array is shared the full array content will be written.

The following code snippet will reproduce this issue:


Code:

osg::Vec2 vec(0.f, 0.f);
osg::Array* sharedArray = new osg::Vec2Array(1, & vec);

// create 2 geometries sharing same array
osg::Geometry* geom0 = new osg::Geometry;
osg::Geometry* geom1 = new osg::Geometry;
geom0->setVertexArray(sharedArray);
geom1->setVertexArray(sharedArray);

osg::ref_ptr<osg::Geode> geode = new osg::Geode;
geode->addDrawable(geom0);
geode->addDrawable(geom1);

std::stringstream buffer;

// write node
osg::ref_ptr<osgDB::Options> options = new osgDB::Options("Ascii");
osgDB::ReaderWriter* rw = osgDB::Registry::instance()->getReaderWriterForExtension("osgt");
osgDB::ReaderWriter::WriteResult wr = rw->writeNode(*geode, buffer, options.get());

// print result; array will be written twice with full content, though with same ID
std::cout << buffer.str() << std::endl;

// trying to read back node will print warnings about unmatched properties
osgDB::ReaderWriter::ReadResult rr = rw->readNode(buffer, options.get());




To fix this i made a change in OutputStream::writeArray().
I think the same issue applies to OutputStream::writeObject(). So i made the same change there.
"
This commit is contained in:
Robert Osfield
2010-09-16 08:46:38 +00:00
parent 94c86d495c
commit 26a41004c2

View File

@@ -140,9 +140,10 @@ void OutputStream::writeArray( const osg::Array* a )
{
if ( !a ) return;
size_t oldSize = _arrayMap.size();
unsigned int id = findOrCreateArrayID( a );
*this << PROPERTY("ArrayID") << id;
if ( id<_arrayMap.size() ) // Shared array
if ( id<=oldSize ) // Shared array
{
*this << std::endl;
return;
@@ -404,6 +405,7 @@ void OutputStream::writeObject( const osg::Object* obj )
std::string name = obj->libraryName();
name += std::string("::") + obj->className();
size_t oldSize = _objectMap.size();
unsigned int id = findOrCreateObjectID( obj );
*this << name << BEGIN_BRACKET << std::endl; // Write object name
@@ -411,7 +413,7 @@ void OutputStream::writeObject( const osg::Object* obj )
if ( getException() ) return;
// Check whether this is a shared object or not
if ( id>=_objectMap.size() )
if ( id>oldSize )
{
ObjectWrapper* wrapper = Registry::instance()->getObjectWrapperManager()->findWrapper( name );
if ( !wrapper )