From 5be155cc4e3fb00a81be884a46d324a065e82b94 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 4 Jan 2002 13:14:06 +0000 Subject: [PATCH] Fixed multiple deletion of shared indecies in GeoSet destructor. --- src/osg/GeoSet.cpp | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/src/osg/GeoSet.cpp b/src/osg/GeoSet.cpp index fde565e12..ead521ae8 100644 --- a/src/osg/GeoSet.cpp +++ b/src/osg/GeoSet.cpp @@ -54,23 +54,45 @@ GeoSet::GeoSet() } -#define INDEX_ARRAY_DELETE(A) if (A._is_ushort) delete [] A._ptr._ushort; else delete [] A._ptr._uint; +#define INDEX_ARRAY_DELETE(A) if (A._is_ushort) ushortList.insert(A._ptr._ushort); else uintList.insert(A._ptr._uint); void GeoSet::AttributeDeleteFunctor::operator() (GeoSet* gset) { // note, delete checks for NULL so want delete NULL pointers. delete [] gset->getPrimLengths(); delete [] gset->getCoords(); - INDEX_ARRAY_DELETE(gset->getCoordIndices()) delete [] gset->getNormals(); - INDEX_ARRAY_DELETE(gset->getNormalIndices()); delete [] gset->getColors(); - INDEX_ARRAY_DELETE(gset->getColorIndices()); delete [] gset->getTextureCoords(); - INDEX_ARRAY_DELETE(gset->getTextureIndices()) // can't delete a void* right now... interleaved arrays needs to be reimplemented with a proper pointer.. // delete [] gset->getInterleavedArray(); + + + // coord indicies may be shared so we have to go through the long winded + // step of creating unique pointer sets which we then delete. This + // ensures that arrays aren't delete twice. Robert. + std::set ushortList; + std::set uintList; + + INDEX_ARRAY_DELETE(gset->getCoordIndices()) + INDEX_ARRAY_DELETE(gset->getNormalIndices()); + INDEX_ARRAY_DELETE(gset->getColorIndices()); + INDEX_ARRAY_DELETE(gset->getTextureIndices()) INDEX_ARRAY_DELETE(gset->getInterleavedIndices()); + + for(std::set::iterator sitr=ushortList.begin(); + sitr!=ushortList.end(); + ++sitr) + { + delete [] *sitr; + } + + for(std::set::iterator iitr=uintList.begin(); + iitr!=uintList.end(); + ++iitr) + { + delete [] *iitr; + } } #undef INDEX_ARRAY_DELETE