From f9f9ea6e156a84a05d903c1963d6737607288f6c Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 6 Sep 2018 11:50:21 +0100 Subject: [PATCH] Fixed memory leak with assignment of default value to ObjectSerializer --- include/osgDB/Serializer | 23 +++++++++++-------- .../serializers/osg/PrimitiveSetIndirect.cpp | 2 +- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/include/osgDB/Serializer b/include/osgDB/Serializer index 4eea99d7e..d25f08ca0 100644 --- a/include/osgDB/Serializer +++ b/include/osgDB/Serializer @@ -551,21 +551,24 @@ public: }; template -class ObjectSerializer : public TemplateSerializer +class ObjectSerializer : public BaseSerializer { public: - typedef TemplateSerializer ParentType; typedef const P* (C::*Getter)() const; typedef void (C::*Setter)( P* ); - ObjectSerializer( const char* name, P* def, Getter gf, Setter sf ) : ParentType(name, def), _getter(gf), _setter(sf) + ObjectSerializer( const char* name, P* def, Getter gf, Setter sf ) : + BaseSerializer(READ_WRITE_PROPERTY), + _name(name), _defaultValue(def), _getter(gf), _setter(sf) { - ParentType::setUsage( _getter!=0, _setter!=0); + setUsage( _getter!=0, _setter!=0); } virtual bool set(osg::Object& obj, void* value) { C& object = OBJECT_CAST(obj); (object.*_setter)( dynamic_cast(*(reinterpret_cast(value))) ); return true; } virtual bool get(const osg::Object& obj, void* value) { const C& object = OBJECT_CAST(obj);*(reinterpret_cast(value )) = dynamic_cast((object.*_getter)()); return true; } + virtual const std::string& getName() const { return _name; } + virtual bool read( InputStream& is, osg::Object& obj ) { C& object = OBJECT_CAST(obj); @@ -579,7 +582,7 @@ public: (object.*_setter)( value.get() ); } } - else if ( is.matchString(ParentType::_name) ) + else if ( is.matchString(_name) ) { is >> hasObject; if ( hasObject ) @@ -606,9 +609,9 @@ public: os.writeObject( value ); } } - else if ( ParentType::_defaultValue!=value ) + else if ( _defaultValue!=value ) { - os << os.PROPERTY((ParentType::_name).c_str()) << hasObject; + os << os.PROPERTY(_name.c_str()) << hasObject; if ( hasObject ) { os << os.BEGIN_BRACKET << std::endl; @@ -621,8 +624,10 @@ public: } public: - Getter _getter; - Setter _setter; + std::string _name; + osg::ref_ptr

_defaultValue; + Getter _getter; + Setter _setter; }; template diff --git a/src/osgWrappers/serializers/osg/PrimitiveSetIndirect.cpp b/src/osgWrappers/serializers/osg/PrimitiveSetIndirect.cpp index 867f57162..fb369d01f 100644 --- a/src/osgWrappers/serializers/osg/PrimitiveSetIndirect.cpp +++ b/src/osgWrappers/serializers/osg/PrimitiveSetIndirect.cpp @@ -135,7 +135,7 @@ REGISTER_OBJECT_WRAPPER( DrawArraysIndirect, osg::DrawArraysIndirect, "osg::Object osg::BufferData osg::PrimitiveSet osg::DrawArraysIndirect" ) { - ADD_OBJECT_SERIALIZER( IndirectCommandArray, osg::IndirectCommandDrawArrays ,new osg::DefaultIndirectCommandDrawArrays()); + ADD_OBJECT_SERIALIZER( IndirectCommandArray, osg::IndirectCommandDrawArrays, new osg::DefaultIndirectCommandDrawArrays()); ADD_UINT_SERIALIZER( FirstCommandToDraw, 0); ADD_INT_SERIALIZER( Stride, 0); }