Hi Gianni,

If you want to remove and add back StateAttribute to a StateSet you have to
mark the StateSet's DataVariance as DYNAMIC, otherwise the draw thread will
overlap the update traversal and contend on the data structure and crash.
Setting DataVariance to DYNAMIC isn't ideal though as it breaks the
multi-threading benefit as it enforces serialization until the last dynamic
StateSet/Drawable is dispatched to OpenGL.  If you use DYNAMIC DataVariance
on Stateset or Drawable you performance is unlikely to benefit too much
from multi-threading but at least it won't crash.

A MUCH better solution, as I suggested, is not to modify the scene graph by
adding/remove stuff, but instead toggle on/off effects by toggle NodeMask
on the multi-pass subgraph, this solution is threadsafe and allows for full
multi-threading.

Robert.


On 26 August 2014 15:28, Gianni Ambrosio <[email protected]> wrote:

> Thanks Robert for the reply.
> I suspected a thread issus but since osgFX::Scribe code does not do
> anything special regarding thread safety I expected my code should work
> fine as well.
>
> Can you see the point in my code? Or maybe a threading issue in OSG code?
> The difference wrt the osgFX::Scribe usage is that the Scribe node is
> removed from the OSG graph in that case instead of removing attributes from
> stateset.
>
>
> Code:
>
>
> osg::ref_ptr< osg::Group > decorator; // class member
>
> Constructor(osg::ref_ptr<osg::Node> iNode)
> {
>    decorator = new osg::Group;
>    decorator->addChild(iNode);
>    iNode->getParent(0)->addChild(decorator);
>
>    osg::StateSet* stateset = decorator->getOrCreateStateSet();
>    osg::Material* material = new osg::Material;
>    stateset->setMode(GL_LIGHTING, osg::StateAttribute::OVERRIDE |
> osg::StateAttribute::OFF);
>    stateset->setAttributeAndModes(material, osg::StateAttribute::OVERRIDE
> | osg::StateAttribute::ON);
> }
>
> void removeWireframe()
> {
>    osg::StateSet* stateset = decorator->getStateSet();
>    stateset->removeAttribute(osg::StateAttribute::POLYGONMODE);
>    stateset->removeAttribute(osg::StateAttribute::POLYGONOFFSET);
> }
>
> void setWireframe()
> {
>    osg::StateSet* stateset = decorator->getStateSet();
>
>    osg::PolygonOffset* polyoffset = new osg::PolygonOffset;
>    polyoffset->setFactor(-1.0f);
>    polyoffset->setUnits(-1.0f);
>    stateset->setAttributeAndModes(polyoffset,
> osg::StateAttribute::OVERRIDE | osg::StateAttribute::ON);
>
>    osg::PolygonMode* polymode = new osg::PolygonMode;
>    polymode->setMode(osg::PolygonMode::FRONT_AND_BACK,
> osg::PolygonMode::LINE);
>    stateset->setAttributeAndModes(polymode, osg::StateAttribute::OVERRIDE
> | osg::StateAttribute::ON);
> }
>
>
>
>
> ------------------
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=60795#60795
>
>
>
>
>
> _______________________________________________
> osg-users mailing list
> [email protected]
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to