Browse Source

prevent crash on exit

David Rose 21 years ago
parent
commit
1058f0fa68
2 changed files with 8 additions and 2 deletions
  1. 7 2
      panda/src/gobj/qpgeomMunger.cxx
  2. 1 0
      panda/src/gobj/qpgeomVertexFormat.cxx

+ 7 - 2
panda/src/gobj/qpgeomMunger.cxx

@@ -66,12 +66,16 @@ remove_format(const qpGeomVertexFormat *format) {
   fi = _formats.find(format);
   nassertv(fi != _formats.end());
 
-  CPT(qpGeomVertexFormat) derived_format = (*fi).second;
+  // We can't save this in a CPT, because it might be the same pointer
+  // as format, which might be in the middle of its destructor.
+  // Putting it in a CPT would bump up its reference count again, and
+  // end up calling the destructor twice.
+  const qpGeomVertexFormat *derived_format = (*fi).second;
   _formats.erase(fi);
 
   // We need to unref the derived format, if we reffed it earlier.
   if (derived_format != format) {
-    derived_format->unref();
+    unref_delete(derived_format);
   }
 }
 
@@ -141,6 +145,7 @@ do_munge_format(const qpGeomVertexFormat *format) {
   {
     qpGeomVertexFormat *f = (qpGeomVertexFormat *)format;
     MutexHolder holder(f->_cache_lock);
+    nassertr(f->is_registered(), NULL);
     inserted = f->_mungers.insert(this).second;
     nassertr(inserted, NULL);
   }

+ 1 - 0
panda/src/gobj/qpgeomVertexFormat.cxx

@@ -84,6 +84,7 @@ qpGeomVertexFormat::
   if (is_registered()) {
     get_registry()->unregister_format(this);
   }
+
   nassertv(_mungers.empty());
 }