Fix memory leak
This commit is contained in:
parent
85c6a2eaf5
commit
55789d5cdf
|
@ -131,19 +131,14 @@ void CollisionDetection::reportCollisionBetweenShapes(CollisionCallback* callbac
|
||||||
ContactPoint* contactPoint = manifold->getContactPoint(i);
|
ContactPoint* contactPoint = manifold->getContactPoint(i);
|
||||||
|
|
||||||
// Create the contact info object for the contact
|
// Create the contact info object for the contact
|
||||||
ContactPointInfo* contactInfo = new (mWorld->mMemoryAllocator.allocate(sizeof(ContactPointInfo)))
|
ContactPointInfo contactInfo(manifold->getShape1(), manifold->getShape2(),
|
||||||
ContactPointInfo(manifold->getShape1(), manifold->getShape2(),
|
contactPoint->getNormal(),
|
||||||
contactPoint->getNormal(),
|
contactPoint->getPenetrationDepth(),
|
||||||
contactPoint->getPenetrationDepth(),
|
contactPoint->getLocalPointOnBody1(),
|
||||||
contactPoint->getLocalPointOnBody1(),
|
contactPoint->getLocalPointOnBody2());
|
||||||
contactPoint->getLocalPointOnBody2());
|
|
||||||
|
|
||||||
// Notify the collision callback about this new contact
|
// Notify the collision callback about this new contact
|
||||||
if (callback != NULL) callback->notifyContact(*contactInfo);
|
if (callback != NULL) callback->notifyContact(contactInfo);
|
||||||
|
|
||||||
// Delete and remove the contact info from the memory allocator
|
|
||||||
contactInfo->~ContactPointInfo();
|
|
||||||
mWorld->mMemoryAllocator.release(contactInfo, sizeof(ContactPointInfo));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -414,7 +409,6 @@ void CollisionDetection::removeProxyCollisionShape(ProxyShape* proxyShape) {
|
||||||
|
|
||||||
// Called by a narrow-phase collision algorithm when a new contact has been found
|
// Called by a narrow-phase collision algorithm when a new contact has been found
|
||||||
void CollisionDetection::notifyContact(OverlappingPair* overlappingPair, const ContactPointInfo& contactInfo) {
|
void CollisionDetection::notifyContact(OverlappingPair* overlappingPair, const ContactPointInfo& contactInfo) {
|
||||||
assert(contactInfo != NULL);
|
|
||||||
|
|
||||||
// If it is the first contact since the pairs are overlapping
|
// If it is the first contact since the pairs are overlapping
|
||||||
if (overlappingPair->getNbContactPoints() == 0) {
|
if (overlappingPair->getNbContactPoints() == 0) {
|
||||||
|
@ -436,7 +430,7 @@ void CollisionDetection::createContact(OverlappingPair* overlappingPair,
|
||||||
|
|
||||||
// Create a new contact
|
// Create a new contact
|
||||||
ContactPoint* contact = new (mWorld->mMemoryAllocator.allocate(sizeof(ContactPoint)))
|
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
|
// Add the contact to the contact manifold set of the corresponding overlapping pair
|
||||||
overlappingPair->addContact(contact);
|
overlappingPair->addContact(contact);
|
||||||
|
|
|
@ -97,6 +97,11 @@ void ContactManifoldSet::addContactPoint(ContactPoint* contact) {
|
||||||
// If we do not want to keep to new manifold (not created yet) with the
|
// If we do not want to keep to new manifold (not created yet) with the
|
||||||
// new contact point
|
// new contact point
|
||||||
if (smallestDepthIndex == -1) {
|
if (smallestDepthIndex == -1) {
|
||||||
|
|
||||||
|
// Delete the new contact
|
||||||
|
contact->~ContactPoint();
|
||||||
|
mMemoryAllocator.release(contact, sizeof(ContactPoint));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user