From 638c928e30bae0163215af4696b9df23b45e9b2b Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sat, 9 Jul 2005 09:56:49 +0000 Subject: [PATCH] From Paul Martz, fix to memory leak of StateSet's --- src/osgPlugins/flt/AttrData.h | 2 +- src/osgPlugins/flt/flt2osg.cpp | 16 +++++++--------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/osgPlugins/flt/AttrData.h b/src/osgPlugins/flt/AttrData.h index 60387f629..7c251e388 100644 --- a/src/osgPlugins/flt/AttrData.h +++ b/src/osgPlugins/flt/AttrData.h @@ -30,7 +30,7 @@ namespace flt { class AttrData : public osg::Object { public: - osg::StateSet *stateset; + osg::ref_ptr stateset; int32 useDetail; // TRUE if using next 5 integers for detail texture int32 txDetail_j; // J argument for TX_DETAIL diff --git a/src/osgPlugins/flt/flt2osg.cpp b/src/osgPlugins/flt/flt2osg.cpp index 4d80689e1..e3178a3a3 100644 --- a/src/osgPlugins/flt/flt2osg.cpp +++ b/src/osgPlugins/flt/flt2osg.cpp @@ -1591,13 +1591,11 @@ void ConvertFromFLT::setTexture ( FaceRecord *rec, SFace *pSFace, osg::StateSet flt::AttrData *textureAttrData = pTexturePool->getTexture(nIndex, versionOptions.get()); - osg::StateSet *textureStateSet; + osg::ref_ptr textureStateSet; if (textureAttrData) textureStateSet = textureAttrData->stateset; - else - textureStateSet = NULL; - if (textureStateSet) + if (textureStateSet.valid()) { //We got detail texture, so we got detailTexture stateset and add a TexEnvCombine attribute // To add simple detail texture we just use texture unit 1 to store detail @@ -1611,7 +1609,7 @@ void ConvertFromFLT::setTexture ( FaceRecord *rec, SFace *pSFace, osg::StateSet int nIndex2 = (int)pSFace->iDetailTexturePattern; detailTextureAttrData = pTexturePool->getTexture(nIndex2,versionOptions.get()); - if (detailTextureAttrData && detailTextureAttrData->stateset) { + if (detailTextureAttrData && detailTextureAttrData->stateset.valid()) { osg::Texture2D *detTexture = dynamic_cast(detailTextureAttrData->stateset->getTextureAttribute( 0, osg::StateAttribute::TEXTURE)); textureStateSet->setTextureAttributeAndModes(1,detTexture,osg::StateAttribute::ON); osg::TexEnvCombine *tec1 = new osg::TexEnvCombine; @@ -1627,7 +1625,7 @@ void ConvertFromFLT::setTexture ( FaceRecord *rec, SFace *pSFace, osg::StateSet // detail texture coordinates get generated later. if (pSFace->iDetailTexturePattern != -1 && detailTextureAttrData && - detailTextureAttrData->stateset) + detailTextureAttrData->stateset.valid()) { // Set the texture coordinate scalars dgset->setDetailTexCoords(detailTextureAttrData->txDetail_m, @@ -1761,10 +1759,10 @@ ConvertFromFLT::addMultiTexture( DynGeoSet* dgset, MultiTextureRecord* mtr ) } // Get the texture state set from the attribute data structure - osg::StateSet *textureStateSet = textureAttrData->stateset; - CERR << "textureStateSet: " << textureStateSet << "\n"; + osg::ref_ptr textureStateSet = textureAttrData->stateset; + CERR << "textureStateSet: " << textureStateSet.get() << "\n"; - if (!textureStateSet) + if (!textureStateSet.valid()) { CERR << "unable to set up multi-texture layer." << std::endl; return;