fix crash when PhysicsManager destructs first

This commit is contained in:
David Rose 2006-03-09 00:14:14 +00:00
parent a524d4db49
commit 5b2e37764a
2 changed files with 8 additions and 3 deletions

View File

@ -23,9 +23,9 @@
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE void PhysicsManager:: INLINE void PhysicsManager::
attach_physical(Physical *p) { attach_physical(Physical *p) {
nassertv(p); nassertv(p && p->_physics_manager == NULL);
p->_physics_manager = this; p->_physics_manager = this;
pvector< Physical * >::iterator found; PhysicalsVector::iterator found;
found = find(_physicals.begin(), _physicals.end(), p); found = find(_physicals.begin(), _physicals.end(), p);
if (found == _physicals.end()) { if (found == _physicals.end()) {
_physicals.push_back(p); _physicals.push_back(p);

View File

@ -45,6 +45,11 @@ PhysicsManager() {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
PhysicsManager:: PhysicsManager::
~PhysicsManager() { ~PhysicsManager() {
PhysicalsVector::iterator pi;
for (pi = _physicals.begin(); pi != _physicals.end(); ++pi) {
nassertv((*pi)->_physics_manager == this);
(*pi)->_physics_manager = NULL;
}
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -115,7 +120,7 @@ remove_physical(Physical *p) {
return; return;
} }
nassertv(*found == p); nassertv(*found == p);
nassertv(p->_physics_manager != (PhysicsManager *) NULL); nassertv(p->_physics_manager == this);
p->_physics_manager = (PhysicsManager *) NULL; p->_physics_manager = (PhysicsManager *) NULL;
_physicals.erase(found); _physicals.erase(found);
nassertv(_physicals.end() == find(_physicals.begin(), _physicals.end(), p)); nassertv(_physicals.end() == find(_physicals.begin(), _physicals.end(), p));