From 83d08b18f809e70ddfa2f506d6c8ea0ff9029711 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 19 Jun 2017 15:45:35 +0100 Subject: [PATCH] Added version checks for when writing out new 64bit object sizes --- src/osgPlugins/osg/BinaryStreamOperator.h | 51 ++++++++++++++++------- 1 file changed, 37 insertions(+), 14 deletions(-) diff --git a/src/osgPlugins/osg/BinaryStreamOperator.h b/src/osgPlugins/osg/BinaryStreamOperator.h index 804d79f8c..929236619 100644 --- a/src/osgPlugins/osg/BinaryStreamOperator.h +++ b/src/osgPlugins/osg/BinaryStreamOperator.h @@ -88,22 +88,45 @@ public: { if ( _supportBinaryBrackets ) { - if ( mark._name=="{" ) + if (getOutputStream() && getOutputStream()->getFileVersion() > 148) { - uint64_t size = 0; - _beginPositions.push_back( _out->tellp() ); - _out->write( (char*)&size, osgDB::INT64_SIZE ); - } - else if ( mark._name=="}" && _beginPositions.size()>0 ) - { - std::streampos pos = _out->tellp(), beginPos = _beginPositions.back(); - _beginPositions.pop_back(); - _out->seekp( beginPos ); + if ( mark._name=="{" ) + { + uint64_t size = 0; + _beginPositions.push_back( _out->tellp() ); + _out->write( (char*)&size, osgDB::INT64_SIZE ); + } + else if ( mark._name=="}" && _beginPositions.size()>0 ) + { + std::streampos pos = _out->tellp(), beginPos = _beginPositions.back(); + _beginPositions.pop_back(); + _out->seekp( beginPos ); - std::streampos size64 = pos - beginPos; - uint64_t size = (uint64_t) size64; - _out->write( (char*)&size, osgDB::INT64_SIZE); - _out->seekp( pos ); + std::streampos size64 = pos - beginPos; + uint64_t size = (uint64_t) size64; + _out->write( (char*)&size, osgDB::INT64_SIZE); + _out->seekp( pos ); + } + } + else + { + if ( mark._name=="{" ) + { + int size = 0; + _beginPositions.push_back( _out->tellp() ); + _out->write( (char*)&size, osgDB::INT_SIZE ); + } + else if ( mark._name=="}" && _beginPositions.size()>0 ) + { + std::streampos pos = _out->tellp(), beginPos = _beginPositions.back(); + _beginPositions.pop_back(); + _out->seekp( beginPos ); + + std::streampos size64 = pos - beginPos; + int size = (int) size64; + _out->write( (char*)&size, osgDB::INT_SIZE); + _out->seekp( pos ); + } } } }