Fix memory leak

This commit is contained in:
Daniel Chappuis 2015-10-15 08:26:33 +02:00
parent 85c6a2eaf5
commit 55789d5cdf
2 changed files with 12 additions and 13 deletions

View File

@ -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(),
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) {

View File

@ -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;
}