fix memory leak

This commit is contained in:
David Rose 2011-09-09 00:14:17 +00:00
parent a4909730dc
commit 0687324183
7 changed files with 58 additions and 17 deletions

View File

@ -121,20 +121,7 @@ determine_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)) {
// 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.
if (express_cat.is_spam()) {
express_cat.spam()
<< "Updating " << get_void_ptr() << " from type "
<< destination << " to type " << refined << "\n";
}
destination = refined;
} else {
// 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;
}

View File

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

View File

@ -27,6 +27,8 @@
#include "clockObject.h"
#include "config_pgraph.h"
TypeHandle CullResult::_type_handle;
// 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.
@ -63,6 +65,9 @@ CullResult(GraphicsStateGuardianBase *gsg,
_gsg(gsg),
_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);
#endif
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
// render it.
bin->add_object(object, current_thread);
} else {
delete object;
}
}

View File

@ -80,6 +80,18 @@ private:
typedef pvector< PT(CullBin) > 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"

View File

@ -22,6 +22,9 @@ INLINE CullableObject::
CullableObject() :
_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)),
_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),
_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),
_fancy(false)
{
#ifdef DO_MEMORY_USAGE
MemoryUsage::update_type(this, get_class_type());
#endif
}
////////////////////////////////////////////////////////////////////

View File

@ -41,7 +41,11 @@ class CullTraverser;
// a number of Geoms to be drawn together, with a number
// 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:
INLINE CullableObject();
INLINE CullableObject(const Geom *geom, const RenderState *state,
@ -151,7 +155,12 @@ public:
return _type_handle;
}
static void init_type() {
#ifdef DO_MEMORY_USAGE
register_type(_type_handle, "CullableObject",
ReferenceCount::get_class_type());
#else
register_type(_type_handle, "CullableObject");
#endif // DO_MEMORY_USAGE
}
private:

View File

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