From d3b88b9e34ae0d46153262ebd1acf2627bb15984 Mon Sep 17 00:00:00 2001 From: Lukasz Gromanowski Date: Sun, 25 Mar 2012 20:37:05 +0200 Subject: [PATCH] Issue #225: Added cleanup of allocated memory in BulletNifLoader and BulletShapeLoader. --- components/nifbullet/bullet_nif_loader.cpp | 22 ++++++++++++++++++-- components/nifbullet/bullet_nif_loader.hpp | 2 +- libs/openengine/bullet/BulletShapeLoader.cpp | 1 + 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/components/nifbullet/bullet_nif_loader.cpp b/components/nifbullet/bullet_nif_loader.cpp index 82e9d7adc..e9aa626db 100644 --- a/components/nifbullet/bullet_nif_loader.cpp +++ b/components/nifbullet/bullet_nif_loader.cpp @@ -51,7 +51,11 @@ using namespace Mangle::VFS; using namespace NifBullet; -//==================================================================================================== +ManualBulletShapeLoader::~ManualBulletShapeLoader() +{ + delete vfs; +} + Ogre::Matrix3 ManualBulletShapeLoader::getMatrix(Nif::Transformation* tr) { Ogre::Matrix3 rot(tr->rotation.v[0].array[0],tr->rotation.v[0].array[1],tr->rotation.v[0].array[2], @@ -135,7 +139,21 @@ void ManualBulletShapeLoader::loadResource(Ogre::Resource *resource) handleNode(node,0,Ogre::Matrix3::IDENTITY,Ogre::Vector3::ZERO,1,hasCollisionNode,false,true); } - currentShape = new btBvhTriangleMeshShape(mTriMesh,true); + struct TriangleMeshShape : public btBvhTriangleMeshShape + { + TriangleMeshShape(btStridingMeshInterface* meshInterface, bool useQuantizedAabbCompression) + : btBvhTriangleMeshShape(meshInterface, useQuantizedAabbCompression) + { + } + + virtual ~TriangleMeshShape() + { + delete getTriangleInfoMap(); + delete m_meshInterface; + } + }; + + currentShape = new TriangleMeshShape(mTriMesh,true); cShape->Shape = currentShape; } diff --git a/components/nifbullet/bullet_nif_loader.hpp b/components/nifbullet/bullet_nif_loader.hpp index 1fa2b6aa5..ed3aceac4 100644 --- a/components/nifbullet/bullet_nif_loader.hpp +++ b/components/nifbullet/bullet_nif_loader.hpp @@ -69,7 +69,7 @@ class ManualBulletShapeLoader : public BulletShapeLoader public: ManualBulletShapeLoader():resourceGroup("General"){vfs = 0;} - virtual ~ManualBulletShapeLoader() {} + virtual ~ManualBulletShapeLoader(); void warn(std::string msg) { diff --git a/libs/openengine/bullet/BulletShapeLoader.cpp b/libs/openengine/bullet/BulletShapeLoader.cpp index 48b87e1e8..4593bad52 100644 --- a/libs/openengine/bullet/BulletShapeLoader.cpp +++ b/libs/openengine/bullet/BulletShapeLoader.cpp @@ -22,6 +22,7 @@ Ogre::Resource(creator, name, handle, group, isManual, loader) BulletShape::~BulletShape() { + deleteShape(Shape); } // farm out to BulletShapeLoader