From 7d318ef1f6e5dc0791f4c89bc542b88e41ed22d2 Mon Sep 17 00:00:00 2001 From: David Rose Date: Wed, 17 Nov 2004 23:35:35 +0000 Subject: [PATCH] fix track-memory-usage error messages --- panda/src/express/memoryInfo.cxx | 48 ++++++++++++++++++++--------- panda/src/express/memoryInfo.h | 4 +-- panda/src/tform/mouseWatcherGroup.h | 4 ++- 3 files changed, 39 insertions(+), 17 deletions(-) diff --git a/panda/src/express/memoryInfo.cxx b/panda/src/express/memoryInfo.cxx index 0ec894af77..87e1f900e8 100644 --- a/panda/src/express/memoryInfo.cxx +++ b/panda/src/express/memoryInfo.cxx @@ -68,12 +68,20 @@ get_type() { TypeHandle type = _static_type; update_type_handle(type, _dynamic_type); + if (type != _static_type) { + if (express_cat.is_spam()) { + express_cat.spam() + << "Pointer " << (void *)_ref_ptr << " has static type " + << _static_type << " and dynamic type " << _dynamic_type << "\n"; + } + } + return type; } //////////////////////////////////////////////////////////////////// // Function: MemoryInfo::determine_dynamic_type -// Access: Public +// Access: Private // Description: Tries to determine the actual type of the object to // which this thing is pointed, if possible. //////////////////////////////////////////////////////////////////// @@ -113,20 +121,36 @@ determine_dynamic_type() { return; } - update_type_handle(_dynamic_type, got_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 " << (void *)_ref_ptr << " from type " + << orig_type << " to type " << _dynamic_type << "\n"; + } + } + + } else { + express_cat.error() + << "Pointer " << (void *)_ref_ptr << " previously indicated as type " + << orig_type << " is now type " << got_type << "!\n"; + } + } } } //////////////////////////////////////////////////////////////////// // Function: MemoryInfo::update_type_handle -// Access: Public +// Access: Private // Description: Updates the given destination TypeHandle with the // refined TypeHandle, if it is in fact more specific -// than the original value for the destination. +// than the original value for the destination. Returns +// true if the update was trouble-free, or false if the +// two types were not apparently related. //////////////////////////////////////////////////////////////////// -void MemoryInfo:: +bool MemoryInfo:: update_type_handle(TypeHandle &destination, TypeHandle refined) { if (refined == TypeHandle::none()) { express_cat.error() @@ -142,19 +166,15 @@ update_type_handle(TypeHandle &destination, TypeHandle refined) { } else if (refined.is_derived_from(destination)) { // Updating with a more-specific type, no problem. - if (express_cat.is_spam()) { - express_cat.spam() - << "Updating pointer " << (void *)_ref_ptr << " from type " - << destination << " to type " << refined << "\n"; - } destination = refined; } else { - express_cat.error() - << "Pointer " << (void *)_ref_ptr << " previously indicated as type " - << destination << " is now type " << refined << "!\n"; + // Unrelated types, which might or might not be a problem. destination = refined; + return false; } + + return true; } #endif // DO_MEMORY_USAGE diff --git a/panda/src/express/memoryInfo.h b/panda/src/express/memoryInfo.h index 6326802bd7..9d1af04979 100644 --- a/panda/src/express/memoryInfo.h +++ b/panda/src/express/memoryInfo.h @@ -55,10 +55,10 @@ public: INLINE double get_time() const; -public: +private: // Members to set up the MemoryInfo structure. void determine_dynamic_type(); - void update_type_handle(TypeHandle &destination, TypeHandle refined); + bool update_type_handle(TypeHandle &destination, TypeHandle refined); private: enum Flags { diff --git a/panda/src/tform/mouseWatcherGroup.h b/panda/src/tform/mouseWatcherGroup.h index 99524d43f9..dcbc1dfc5d 100644 --- a/panda/src/tform/mouseWatcherGroup.h +++ b/panda/src/tform/mouseWatcherGroup.h @@ -48,10 +48,12 @@ protected: public: static TypeHandle get_class_type() { + ReferenceCount::init_type(); return _type_handle; } static void init_type() { - register_type(_type_handle, "MouseWatcherGroup"); + register_type(_type_handle, "MouseWatcherGroup", + ReferenceCount::get_class_type()); } private: