ソースを参照

fix crash when PhysicsManager destructs first

David Rose 20 年 前
コミット
5b2e37764a

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

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

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

@@ -45,6 +45,11 @@ 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;
   }
   nassertv(*found == p);
-  nassertv(p->_physics_manager != (PhysicsManager *) NULL);
+  nassertv(p->_physics_manager == this);
   p->_physics_manager = (PhysicsManager *) NULL;
   _physicals.erase(found);
   nassertv(_physicals.end() == find(_physicals.begin(), _physicals.end(), p));