From 26a41004c2c3f7f2cd5fb7f94aba814d2c72a163 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 16 Sep 2010 08:46:38 +0000 Subject: [PATCH] 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 geode = new osg::Geode; geode->addDrawable(geom0); geode->addDrawable(geom1); std::stringstream buffer; // write node osg::ref_ptr 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. " --- src/osgDB/OutputStream.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/osgDB/OutputStream.cpp b/src/osgDB/OutputStream.cpp index 4d87b63e2..bd67e84f7 100644 --- a/src/osgDB/OutputStream.cpp +++ b/src/osgDB/OutputStream.cpp @@ -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 )