fix track-memory-usage error messages

This commit is contained in:
David Rose 2004-11-17 23:35:35 +00:00
parent acde259015
commit 7d318ef1f6
3 changed files with 39 additions and 17 deletions

View File

@ -68,12 +68,20 @@ get_type() {
TypeHandle type = _static_type; TypeHandle type = _static_type;
update_type_handle(type, _dynamic_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; return type;
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: MemoryInfo::determine_dynamic_type // Function: MemoryInfo::determine_dynamic_type
// Access: Public // Access: Private
// Description: Tries to determine the actual type of the object to // Description: Tries to determine the actual type of the object to
// which this thing is pointed, if possible. // which this thing is pointed, if possible.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -113,20 +121,36 @@ determine_dynamic_type() {
return; 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 // Function: MemoryInfo::update_type_handle
// Access: Public // Access: Private
// Description: Updates the given destination TypeHandle with the // Description: Updates the given destination TypeHandle with the
// refined TypeHandle, if it is in fact more specific // 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) { update_type_handle(TypeHandle &destination, TypeHandle refined) {
if (refined == TypeHandle::none()) { if (refined == TypeHandle::none()) {
express_cat.error() express_cat.error()
@ -142,19 +166,15 @@ update_type_handle(TypeHandle &destination, TypeHandle refined) {
} else if (refined.is_derived_from(destination)) { } else if (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 pointer " << (void *)_ref_ptr << " from type "
<< destination << " to type " << refined << "\n";
}
destination = refined; destination = refined;
} else { } else {
express_cat.error() // Unrelated types, which might or might not be a problem.
<< "Pointer " << (void *)_ref_ptr << " previously indicated as type "
<< destination << " is now type " << refined << "!\n";
destination = refined; destination = refined;
return false;
} }
return true;
} }
#endif // DO_MEMORY_USAGE #endif // DO_MEMORY_USAGE

View File

@ -55,10 +55,10 @@ public:
INLINE double get_time() const; INLINE double get_time() const;
public: private:
// Members to set up the MemoryInfo structure. // Members to set up the MemoryInfo structure.
void determine_dynamic_type(); void determine_dynamic_type();
void update_type_handle(TypeHandle &destination, TypeHandle refined); bool update_type_handle(TypeHandle &destination, TypeHandle refined);
private: private:
enum Flags { enum Flags {

View File

@ -48,10 +48,12 @@ protected:
public: public:
static TypeHandle get_class_type() { static TypeHandle get_class_type() {
ReferenceCount::init_type();
return _type_handle; return _type_handle;
} }
static void init_type() { static void init_type() {
register_type(_type_handle, "MouseWatcherGroup"); register_type(_type_handle, "MouseWatcherGroup",
ReferenceCount::get_class_type());
} }
private: private: