Browse Source

fix crash when PhysicsManager destructs first

David Rose 20 years ago
parent
commit
5b2e37764a
2 changed files with 8 additions and 3 deletions
  1. 2 2
      panda/src/physics/physicsManager.I
  2. 6 1
      panda/src/physics/physicsManager.cxx

+ 2 - 2
panda/src/physics/physicsManager.I

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

+ 6 - 1
panda/src/physics/physicsManager.cxx

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