From 55789d5cdf2566705c2e66bab66b98649d678b03 Mon Sep 17 00:00:00 2001 From: Daniel Chappuis Date: Thu, 15 Oct 2015 08:26:33 +0200 Subject: [PATCH] Fix memory leak --- src/collision/CollisionDetection.cpp | 20 +++++++------------- src/collision/ContactManifoldSet.cpp | 5 +++++ 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/collision/CollisionDetection.cpp b/src/collision/CollisionDetection.cpp index 673d4539..5d229e25 100644 --- a/src/collision/CollisionDetection.cpp +++ b/src/collision/CollisionDetection.cpp @@ -131,19 +131,14 @@ void CollisionDetection::reportCollisionBetweenShapes(CollisionCallback* callbac ContactPoint* contactPoint = manifold->getContactPoint(i); // Create the contact info object for the contact - ContactPointInfo* contactInfo = new (mWorld->mMemoryAllocator.allocate(sizeof(ContactPointInfo))) - ContactPointInfo(manifold->getShape1(), manifold->getShape2(), - contactPoint->getNormal(), - contactPoint->getPenetrationDepth(), - contactPoint->getLocalPointOnBody1(), - contactPoint->getLocalPointOnBody2()); + ContactPointInfo contactInfo(manifold->getShape1(), manifold->getShape2(), + contactPoint->getNormal(), + contactPoint->getPenetrationDepth(), + contactPoint->getLocalPointOnBody1(), + contactPoint->getLocalPointOnBody2()); // Notify the collision callback about this new contact - if (callback != NULL) callback->notifyContact(*contactInfo); - - // Delete and remove the contact info from the memory allocator - contactInfo->~ContactPointInfo(); - mWorld->mMemoryAllocator.release(contactInfo, sizeof(ContactPointInfo)); + if (callback != NULL) callback->notifyContact(contactInfo); } } } @@ -414,7 +409,6 @@ void CollisionDetection::removeProxyCollisionShape(ProxyShape* proxyShape) { // Called by a narrow-phase collision algorithm when a new contact has been found void CollisionDetection::notifyContact(OverlappingPair* overlappingPair, const ContactPointInfo& contactInfo) { - assert(contactInfo != NULL); // If it is the first contact since the pairs are overlapping if (overlappingPair->getNbContactPoints() == 0) { @@ -436,7 +430,7 @@ void CollisionDetection::createContact(OverlappingPair* overlappingPair, // Create a new contact ContactPoint* contact = new (mWorld->mMemoryAllocator.allocate(sizeof(ContactPoint))) - ContactPoint(contactInfo); + ContactPoint(contactInfo); // Add the contact to the contact manifold set of the corresponding overlapping pair overlappingPair->addContact(contact); diff --git a/src/collision/ContactManifoldSet.cpp b/src/collision/ContactManifoldSet.cpp index 49362032..cfb65e86 100644 --- a/src/collision/ContactManifoldSet.cpp +++ b/src/collision/ContactManifoldSet.cpp @@ -97,6 +97,11 @@ void ContactManifoldSet::addContactPoint(ContactPoint* contact) { // If we do not want to keep to new manifold (not created yet) with the // new contact point if (smallestDepthIndex == -1) { + + // Delete the new contact + contact->~ContactPoint(); + mMemoryAllocator.release(contact, sizeof(ContactPoint)); + return; }