Browse Source

fix memory leak

David Rose 14 years ago
parent
commit
0687324183

+ 11 - 15
panda/src/express/memoryInfo.cxx

@@ -121,20 +121,7 @@ determine_dynamic_type() {
       }
       }
 
 
       TypeHandle orig_type = _dynamic_type;
       TypeHandle orig_type = _dynamic_type;
-      if (update_type_handle(_dynamic_type, got_type)) {
-        if (orig_type != _dynamic_type) {
-          if (express_cat.is_spam()) {
-            express_cat.spam()
-              << "Updating " << get_void_ptr() << " from type "
-              << orig_type << " to type " << _dynamic_type << "\n";
-          }
-        }
-
-      } else {
-        express_cat.warning()
-          << "Pointer " << get_void_ptr() << " previously indicated as type "
-          << orig_type << " is now type " << got_type << "!\n";
-      }
+      update_type_handle(_dynamic_type, got_type);
     }    
     }    
   }
   }
 }
 }
@@ -163,12 +150,21 @@ update_type_handle(TypeHandle &destination, TypeHandle refined) {
   } else if (destination.is_derived_from(refined)) {
   } else if (destination.is_derived_from(refined)) {
     // Updating with a less-specific type, no problem.
     // Updating with a less-specific type, no problem.
 
 
-  } else if (refined.is_derived_from(destination)) {
+  } else if (destination == TypeHandle::none() || 
+             refined.is_derived_from(destination)) {
     // Updating with a more-specific type, no problem.
     // Updating with a more-specific type, no problem.
+    if (express_cat.is_spam()) {
+      express_cat.spam()
+        << "Updating " << get_void_ptr() << " from type "
+        << destination << " to type " << refined << "\n";
+    }
     destination = refined;
     destination = refined;
 
 
   } else {
   } else {
     // Unrelated types, which might or might not be a problem.
     // Unrelated types, which might or might not be a problem.
+    express_cat.warning()
+      << "Pointer " << get_void_ptr() << " previously indicated as type "
+      << destination << " is now type " << refined << "!\n";
     return false;
     return false;
   }
   }
   
   

+ 2 - 0
panda/src/pgraph/config_pgraph.cxx

@@ -30,6 +30,7 @@
 #include "cullFaceAttrib.h"
 #include "cullFaceAttrib.h"
 #include "cullBin.h"
 #include "cullBin.h"
 #include "cullBinAttrib.h"
 #include "cullBinAttrib.h"
+#include "cullResult.h"
 #include "cullTraverser.h"
 #include "cullTraverser.h"
 #include "cullableObject.h"
 #include "cullableObject.h"
 #include "decalEffect.h"
 #include "decalEffect.h"
@@ -449,6 +450,7 @@ init_libpgraph() {
   CullFaceAttrib::init_type();
   CullFaceAttrib::init_type();
   CullBin::init_type();
   CullBin::init_type();
   CullBinAttrib::init_type();
   CullBinAttrib::init_type();
+  CullResult::init_type();
   CullTraverser::init_type();
   CullTraverser::init_type();
   CullableObject::init_type();
   CullableObject::init_type();
   DecalEffect::init_type();
   DecalEffect::init_type();

+ 9 - 0
panda/src/pgraph/cullResult.cxx

@@ -27,6 +27,8 @@
 #include "clockObject.h"
 #include "clockObject.h"
 #include "config_pgraph.h"
 #include "config_pgraph.h"
 
 
+TypeHandle CullResult::_type_handle;
+
 // This value is used instead of 1.0 to represent the alpha level of a
 // This value is used instead of 1.0 to represent the alpha level of a
 // pixel that is to be considered "opaque" for the purposes of M_dual.
 // pixel that is to be considered "opaque" for the purposes of M_dual.
 
 
@@ -63,6 +65,9 @@ CullResult(GraphicsStateGuardianBase *gsg,
   _gsg(gsg),
   _gsg(gsg),
   _draw_region_pcollector(draw_region_pcollector)
   _draw_region_pcollector(draw_region_pcollector)
 {
 {
+#ifdef DO_MEMORY_USAGE
+  MemoryUsage::update_type(this, get_class_type());
+#endif
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -186,6 +191,8 @@ add_object(CullableObject *object, const CullTraverser *traverser) {
                 check_flash_bin(transparent_part->_state, bin);
                 check_flash_bin(transparent_part->_state, bin);
 #endif
 #endif
                 bin->add_object(transparent_part, current_thread);
                 bin->add_object(transparent_part, current_thread);
+              } else {
+                delete transparent_part;
               }
               }
             }
             }
           
           
@@ -225,6 +232,8 @@ add_object(CullableObject *object, const CullTraverser *traverser) {
     // already loaded.  We'll let the GSG ultimately decide whether to
     // already loaded.  We'll let the GSG ultimately decide whether to
     // render it.
     // render it.
     bin->add_object(object, current_thread);
     bin->add_object(object, current_thread);
+  } else {
+    delete object;
   }
   }
 }
 }
 
 

+ 12 - 0
panda/src/pgraph/cullResult.h

@@ -80,6 +80,18 @@ private:
   
   
   typedef pvector< PT(CullBin) > Bins;
   typedef pvector< PT(CullBin) > Bins;
   Bins _bins;
   Bins _bins;
+
+public:
+  static TypeHandle get_class_type() {
+    return _type_handle;
+  }
+  static void init_type() {
+    register_type(_type_handle, "CullResult",
+                  ReferenceCount::get_class_type());
+  }
+  
+private:
+  static TypeHandle _type_handle;
 };
 };
 
 
 #include "cullResult.I"
 #include "cullResult.I"

+ 12 - 0
panda/src/pgraph/cullableObject.I

@@ -22,6 +22,9 @@ INLINE CullableObject::
 CullableObject() :
 CullableObject() :
   _fancy(false)
   _fancy(false)
 {
 {
+#ifdef DO_MEMORY_USAGE
+  MemoryUsage::update_type(this, get_class_type());
+#endif
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -42,6 +45,9 @@ CullableObject(const Geom *geom, const RenderState *state,
   _internal_transform(gsg->get_cs_transform()->compose(modelview_transform)),
   _internal_transform(gsg->get_cs_transform()->compose(modelview_transform)),
   _fancy(false)
   _fancy(false)
 {
 {
+#ifdef DO_MEMORY_USAGE
+  MemoryUsage::update_type(this, get_class_type());
+#endif
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -62,6 +68,9 @@ CullableObject(const Geom *geom, const RenderState *state,
   _internal_transform(internal_transform),
   _internal_transform(internal_transform),
   _fancy(false)
   _fancy(false)
 {
 {
+#ifdef DO_MEMORY_USAGE
+  MemoryUsage::update_type(this, get_class_type());
+#endif
 }
 }
   
   
 
 
@@ -82,6 +91,9 @@ CullableObject(const CullableObject &copy) :
   _internal_transform(copy._internal_transform),
   _internal_transform(copy._internal_transform),
   _fancy(false)
   _fancy(false)
 {
 {
+#ifdef DO_MEMORY_USAGE
+  MemoryUsage::update_type(this, get_class_type());
+#endif
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////

+ 10 - 1
panda/src/pgraph/cullableObject.h

@@ -41,7 +41,11 @@ class CullTraverser;
 //               a number of Geoms to be drawn together, with a number
 //               a number of Geoms to be drawn together, with a number
 //               of Geoms decalled onto them.
 //               of Geoms decalled onto them.
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
-class EXPCL_PANDA_PGRAPH CullableObject {
+class EXPCL_PANDA_PGRAPH CullableObject 
+#ifdef DO_MEMORY_USAGE
+  : public ReferenceCount   // We inherit from ReferenceCount just to get the memory type tracking that MemoryUsage provides.
+#endif  // DO_MEMORY_USAGE
+{
 public:
 public:
   INLINE CullableObject();
   INLINE CullableObject();
   INLINE CullableObject(const Geom *geom, const RenderState *state,
   INLINE CullableObject(const Geom *geom, const RenderState *state,
@@ -151,7 +155,12 @@ public:
     return _type_handle;
     return _type_handle;
   }
   }
   static void init_type() {
   static void init_type() {
+#ifdef DO_MEMORY_USAGE
+    register_type(_type_handle, "CullableObject",
+                  ReferenceCount::get_class_type());
+#else
     register_type(_type_handle, "CullableObject");
     register_type(_type_handle, "CullableObject");
+#endif  // DO_MEMORY_USAGE
   }
   }
 
 
 private:
 private:

+ 2 - 1
panda/src/putil/clockObject.h

@@ -171,7 +171,8 @@ public:
     return _type_handle;
     return _type_handle;
   }
   }
   static void init_type() {
   static void init_type() {
-    register_type(_type_handle, "ClockObject");
+    register_type(_type_handle, "ClockObject",
+                  ReferenceCount::get_class_type());
   }
   }
 
 
 private:
 private: