Fix memory leaks in Map and Set classes

This commit is contained in:
Daniel Chappuis 2021-08-13 16:52:17 +02:00
parent e6518f6e87
commit 6db3674c65
4 changed files with 80 additions and 65 deletions

View File

@ -62,6 +62,7 @@ do not hesitate to take a look at the user manual.
- Issue with wrong linear velocity update computed in RigidBody::setLocalCenterOfMass() method
- Issue with wrong linear velocity update computed in RigidBody::updateLocalCenterOfMassFromColliders() method
- Issue with wrong linear velocity update computed in RigidBody::updateMassPropertiesFromColliders() method
- Issue in copy-constructors in Map and Set classes
## Version 0.8.0 (May 31, 2020)

View File

@ -239,6 +239,8 @@ class Map {
:mNbAllocatedEntries(map.mNbAllocatedEntries), mNbEntries(map.mNbEntries), mHashSize(map.mHashSize),
mBuckets(nullptr), mEntries(nullptr), mNextEntries(nullptr), mAllocator(map.mAllocator), mFreeIndex(map.mFreeIndex) {
if (mHashSize > 0) {
// Allocate memory for the buckets
mBuckets = static_cast<uint32*>(mAllocator.allocate(mHashSize * sizeof(uint32)));
@ -265,6 +267,7 @@ class Map {
}
}
}
}
/// Destructor
~Map() {
@ -640,6 +643,8 @@ class Map {
mHashSize = map.mHashSize;
mFreeIndex = map.mFreeIndex;
if (mHashSize > 0) {
// Allocate memory for the buckets
mBuckets = static_cast<uint32*>(mAllocator.allocate(mHashSize * sizeof(uint32)));
@ -666,6 +671,7 @@ class Map {
}
}
}
}
return *this;
}

View File

@ -239,6 +239,8 @@ class Set {
:mNbAllocatedEntries(set.mNbAllocatedEntries), mNbEntries(set.mNbEntries), mHashSize(set.mHashSize),
mBuckets(nullptr), mEntries(nullptr), mNextEntries(nullptr), mAllocator(set.mAllocator), mFreeIndex(set.mFreeIndex) {
if (mHashSize > 0) {
// Allocate memory for the buckets
mBuckets = static_cast<uint32*>(mAllocator.allocate(mHashSize * sizeof(uint32)));
@ -265,6 +267,7 @@ class Set {
}
}
}
}
/// Destructor
~Set() {
@ -604,6 +607,8 @@ class Set {
mHashSize = set.mHashSize;
mFreeIndex = set.mFreeIndex;
if (mHashSize > 0) {
// Allocate memory for the buckets
mBuckets = static_cast<uint32*>(mAllocator.allocate(mHashSize * sizeof(uint32)));
@ -630,6 +635,7 @@ class Set {
}
}
}
}
return *this;
}

View File

@ -58,7 +58,6 @@ class TestRigidBody : public Test {
PolygonVertexArray* mConvexMeshPolygonVertexArray;
PolyhedronMesh* mConvexMeshPolyhedronMesh;
PolygonVertexArray::PolygonFace* mConvexMeshPolygonFaces;
TriangleVertexArray* mConcaveMeshTriangleVertexArray;
float mConvexMeshCubeVertices[8 * 3];
int mConvexMeshCubeIndices[24];
@ -137,6 +136,9 @@ class TestRigidBody : public Test {
mWorld->destroyRigidBody(mRigidBody1);
mWorld->destroyRigidBody(mRigidBody2Box);
mWorld->destroyRigidBody(mRigidBody2Sphere);
delete[] mConvexMeshPolygonFaces;
delete mConvexMeshPolygonVertexArray;
}
/// Run the tests