Canvas: Fix crash on hide/show after detaching element from scenegraph.

This commit is contained in:
Thomas Geymayer 2014-02-22 01:44:29 +01:00
parent 94bbed80d0
commit b2cedc5332
2 changed files with 16 additions and 7 deletions

View File

@ -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);
}
//----------------------------------------------------------------------------

View File

@ -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;