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;
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,7 +121,21 @@ 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";
}
}
}
}
@ -121,12 +143,14 @@ determine_dynamic_type() {
////////////////////////////////////////////////////////////////////
// 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

View File

@ -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 {

View File

@ -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: