]> git.mxchange.org Git - simgear.git/commitdiff
canvas::Element: check if element is valid.
authorThomas Geymayer <tomgey@gmail.com>
Sun, 15 Jun 2014 14:30:57 +0000 (16:30 +0200)
committerThomas Geymayer <tomgey@gmail.com>
Sun, 15 Jun 2014 14:30:57 +0000 (16:30 +0200)
simgear/canvas/elements/CanvasElement.cxx

index d67ba4f2df70071344c4df3d210a44c1da243f0d..98f93343bc2c1858fd419751c3ef748662fdf0e5 100644 (file)
@@ -229,7 +229,7 @@ namespace canvas
     if( dt == 0 && _drawable )
       _drawable->getBound();
 
-    if( _attributes_dirty & BLEND_FUNC )
+    if( (_attributes_dirty & BLEND_FUNC) && _transform.valid() )
     {
       parseBlendFunc(
         _transform->getOrCreateStateSet(),
@@ -512,9 +512,13 @@ namespace canvas
   //----------------------------------------------------------------------------
   void Element::setClip(const std::string& clip)
   {
+    osg::StateSet* ss = getOrCreateStateSet();
+    if( !ss )
+      return;
+
     if( clip.empty() || clip == "auto" )
     {
-      getOrCreateStateSet()->removeAttribute(osg::StateAttribute::SCISSOR);
+      ss->removeAttribute(osg::StateAttribute::SCISSOR);
       _scissor = 0;
       return;
     }
@@ -576,7 +580,7 @@ namespace canvas
     else
       _scissor->_coord_reference = GLOBAL;
 
-    getOrCreateStateSet()->setAttributeAndModes(_scissor);
+    ss->setAttributeAndModes(_scissor);
   }
 
   //----------------------------------------------------------------------------
@@ -821,8 +825,12 @@ namespace canvas
   //----------------------------------------------------------------------------
   osg::StateSet* Element::getOrCreateStateSet()
   {
-    return _drawable ? _drawable->getOrCreateStateSet()
-                     : _transform->getOrCreateStateSet();
+    if( _drawable.valid() )
+      return _drawable->getOrCreateStateSet();
+    if( _transform.valid() )
+      return _transform->getOrCreateStateSet();
+
+    return 0;
   }
 
   //----------------------------------------------------------------------------