From: Thomas Geymayer Date: Sun, 10 Nov 2013 16:12:50 +0000 (+0100) Subject: CanvasElement: ensure parent pointer can not become invalid. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=743244a69cd37d5981fc5603af58d19cc07c0f72;p=simgear.git CanvasElement: ensure parent pointer can not become invalid. --- diff --git a/simgear/canvas/elements/CanvasElement.cxx b/simgear/canvas/elements/CanvasElement.cxx index 49c7a47b..b6e83056 100644 --- a/simgear/canvas/elements/CanvasElement.cxx +++ b/simgear/canvas/elements/CanvasElement.cxx @@ -108,7 +108,19 @@ namespace canvas //---------------------------------------------------------------------------- Element::~Element() { + if( !_transform.valid() ) + return; + for(unsigned int i = 0; i < _transform->getNumChildren(); ++i) + { + OSGUserData* ud = + static_cast(_transform->getChild(i)->getUserData()); + + if( ud ) + // Ensure parent is cleared to prevent accessing released memory if an + // element somehow survives longer than his parent. + ud->element->_parent = 0; + } } //----------------------------------------------------------------------------