From: ThorstenB Date: Mon, 7 Mar 2011 18:32:20 +0000 (+0100) Subject: Catch dangling property ties. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=10bbd435b7c82d15b040c44c81b6dcda5ecbc706;p=simgear.git Catch dangling property ties. It's bad when tied properties are not untied before removing the tied property list. We could try to "untie" the properties in the destructor - but that usually caused weird mem access errors, since the tied properties will access a no longer existing object (the very object whose destruction called the TiedPropertyList destructor...). => so just add a warning and a nagging trap :) --- diff --git a/simgear/props/tiedpropertylist.hxx b/simgear/props/tiedpropertylist.hxx index 28cdb518..c825d105 100644 --- a/simgear/props/tiedpropertylist.hxx +++ b/simgear/props/tiedpropertylist.hxx @@ -21,6 +21,7 @@ #ifndef __TIEDPROPERTYLIST_HXX #define __TIEDPROPERTYLIST_HXX #include +#include using simgear::PropertyList; namespace simgear { @@ -34,6 +35,16 @@ class TiedPropertyList : PropertyList { public: TiedPropertyList() {} TiedPropertyList( SGPropertyNode_ptr root ) : _root(root) {} + virtual ~TiedPropertyList() + { + _root = 0; + if (size()>0) + { + SG_LOG(SG_GENERAL, SG_ALERT, "Detected properties with dangling ties. Use 'Untie' before removing a TiedPropertyList."); + // running debug mode: go, fix it! + assert(size() == 0); + } + } void setRoot( SGPropertyNode_ptr root ) { _root = root; } SGPropertyNode_ptr getRoot() const { return _root; }