From: Thomas Geymayer Date: Sat, 22 Feb 2014 00:44:29 +0000 (+0100) Subject: Canvas: Fix crash on hide/show after detaching element from scenegraph. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=b2cedc5332b82f235d10a6344d23b2df0887539f;p=simgear.git Canvas: Fix crash on hide/show after detaching element from scenegraph. --- diff --git a/simgear/canvas/elements/CanvasElement.cxx b/simgear/canvas/elements/CanvasElement.cxx index 34088814..44dffc54 100644 --- a/simgear/canvas/elements/CanvasElement.cxx +++ b/simgear/canvas/elements/CanvasElement.cxx @@ -163,8 +163,7 @@ namespace canvas //---------------------------------------------------------------------------- void Element::update(double dt) { - if( !_transform->getNodeMask() ) - // Don't do anything if element is hidden + if( !isVisible() ) return; // Trigger matrix update @@ -278,6 +277,14 @@ namespace canvas return _transform->getBound().contains(osg::Vec3f(pos, 0)); } + //---------------------------------------------------------------------------- + void Element::setVisible(bool visible) + { + if( _transform.valid() ) + // TODO check if we need another nodemask + _transform->setNodeMask(visible ? 0xffffffff : 0); + } + //---------------------------------------------------------------------------- bool Element::isVisible() const { @@ -393,9 +400,6 @@ namespace canvas } else if( name == "update" ) return update(0); - else if( name == "visible" ) - // TODO check if we need another nodemask - return _transform->setNodeMask( child->getBoolValue() ? 0xffffffff : 0 ); else if( boost::starts_with(name, "blend-") ) return (void)(_attributes_dirty |= BLEND_FUNC); } @@ -636,6 +640,7 @@ namespace canvas addStyle("clip", "", &Element::setClip, false); addStyle("clip-frame", "", &Element::setClipFrame, false); + addStyle("visible", "", &Element::setVisible, false); } //---------------------------------------------------------------------------- diff --git a/simgear/canvas/elements/CanvasElement.hxx b/simgear/canvas/elements/CanvasElement.hxx index e56a943c..79a6265b 100644 --- a/simgear/canvas/elements/CanvasElement.hxx +++ b/simgear/canvas/elements/CanvasElement.hxx @@ -117,8 +117,12 @@ namespace canvas const osg::Vec2f& local_pos ) const; /** - * Get whether the element is visible or hidden (Can be changed with - * setting property "visible" accordingly). + * Set visibility of the element. + */ + void setVisible(bool visible); + + /** + * Get whether the element is visible or hidden. */ bool isVisible() const;