Fix potential iterator invalidation

This commit is contained in:
Atlante45 2016-05-05 15:04:39 -07:00
parent ec50744aa1
commit f65b15803a

View file

@ -225,9 +225,7 @@ void PhysicsEngine::removeContacts(ObjectMotionState* motionState) {
ContactMap::iterator contactItr = _contactMap.begin(); ContactMap::iterator contactItr = _contactMap.begin();
while (contactItr != _contactMap.end()) { while (contactItr != _contactMap.end()) {
if (contactItr->first._a == motionState || contactItr->first._b == motionState) { if (contactItr->first._a == motionState || contactItr->first._b == motionState) {
ContactMap::iterator iterToDelete = contactItr; contactItr = _contactMap.erase(contactItr);
++contactItr;
_contactMap.erase(iterToDelete);
} else { } else {
++contactItr; ++contactItr;
} }
@ -386,9 +384,7 @@ const CollisionEvents& PhysicsEngine::getCollisionEvents() {
} }
if (type == CONTACT_EVENT_TYPE_END) { if (type == CONTACT_EVENT_TYPE_END) {
ContactMap::iterator iterToDelete = contactItr; contactItr = _contactMap.erase(contactItr);
++contactItr;
_contactMap.erase(iterToDelete);
} else { } else {
++contactItr; ++contactItr;
} }