From 743244a69cd37d5981fc5603af58d19cc07c0f72 Mon Sep 17 00:00:00 2001 From: Thomas Geymayer Date: Sun, 10 Nov 2013 17:12:50 +0100 Subject: [PATCH] CanvasElement: ensure parent pointer can not become invalid. --- simgear/canvas/elements/CanvasElement.cxx | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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; + } } //---------------------------------------------------------------------------- -- 2.39.5