]> git.mxchange.org Git - simgear.git/commitdiff
CanvasElement: ensure parent pointer can not become invalid.
authorThomas Geymayer <tomgey@gmail.com>
Sun, 10 Nov 2013 16:12:50 +0000 (17:12 +0100)
committerThomas Geymayer <tomgey@gmail.com>
Sun, 10 Nov 2013 16:12:50 +0000 (17:12 +0100)
simgear/canvas/elements/CanvasElement.cxx

index 49c7a47b50288c3844b80a5fca1a2f03c36f0fbc..b6e830569db5453395d148f4f7a703691614cf6d 100644 (file)
@@ -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<OSGUserData*>(_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;
+    }
   }
 
   //----------------------------------------------------------------------------