Fixed memory leak

This commit is contained in:
Robert Osfield 2016-06-10 19:25:07 +01:00
parent 358a882031
commit 8fe37bdf63
2 changed files with 12 additions and 11 deletions

View File

@ -369,7 +369,6 @@ ref_ptr<Group> VBSPEntity::createBrushGeometry()
{
int i;
int numGeoms;
VBSPGeometry ** vbspGeomList;
Model currentModel;
Face currentFace;
TexInfo currentTexInfo;
@ -387,11 +386,11 @@ ref_ptr<Group> VBSPEntity::createBrushGeometry()
// convert them back into OSG geometry objects. We potentially will need
// one for each state set in the map
numGeoms = bsp_data->getNumStateSets();
vbspGeomList = new VBSPGeometry *[numGeoms];
// Initialize the list to all NULL for now. We'll create the geometry
// objects as we need them
memset(vbspGeomList, 0, sizeof(VBSPGeometry *) * numGeoms);
typedef std::vector< osg::ref_ptr<VBSPGeometry> > VBSPGeometryList;
VBSPGeometryList vbspGeomList;
vbspGeomList.resize(numGeoms);
// Get this entity's internal model from the bsp data
currentModel = bsp_data->getModel(entity_model_index);
@ -435,12 +434,13 @@ ref_ptr<Group> VBSPEntity::createBrushGeometry()
// Get or create the corresponding VBSPGeometry object from the
// list
currentGeomIndex = currentTexInfo.texdata_index;
currentGeom = vbspGeomList[currentGeomIndex];
currentGeom = vbspGeomList[currentGeomIndex].get();
if (currentGeom == NULL)
{
// Create the geometry object
vbspGeomList[currentGeomIndex] = new VBSPGeometry(bsp_data);
currentGeom = vbspGeomList[currentGeomIndex];
currentGeom = vbspGeomList[currentGeomIndex].get();
}
// Add the face to the appropriate VBSPGeometry object
@ -484,7 +484,7 @@ ref_ptr<Group> VBSPEntity::createBrushGeometry()
for (i = 0; i < numGeoms; i++)
{
// Get the next geometry object (if any)
currentGeom = vbspGeomList[i];
currentGeom = vbspGeomList[i].get();
if (currentGeom != NULL)
{
// Convert the BSP geometry to OSG geometry

View File

@ -13,7 +13,7 @@ namespace bsp
{
class VBSPGeometry
class VBSPGeometry : public osg::Referenced
{
protected:
@ -37,10 +37,11 @@ class VBSPGeometry
int firstVertex, int vertsPerEdge);
void createDispSurface(Face & face, DisplaceInfo & dispInfo);
public:
virtual ~VBSPGeometry();
public:
VBSPGeometry(VBSPData * bspData);
virtual ~VBSPGeometry();
void addFace(int faceIndex);
osg::ref_ptr<osg::Group> createGeometry();