[osg-users] osg::Drawable::DrawCallback issue

2 views
Skip to first unread message

Harold Comere

unread,
Nov 20, 2009, 4:43:55 AM11/20/09
to OpenSceneGraph Users
Hi all,

I am currently experiencing some issues to update often the text of an osgText::Text. I m working with osg 2.8.1.

While draging the mouse i need to update the text of an osgText, so this update is called very often.
So i have done a class inherating of osg::Drawable::DrawCallback, wich i attach to my osgText::Text as an update callback :
And in the following code ClassC is a class inherating of osg::Geode and containing the osgText.

When the mouse is draging i set a flag _needUpdate of my ClassC class to true, then text is updated in the callback if needed.

    class TextDrawCallback : public virtual osg::Drawable::DrawCallback
    {
    private:
        osg::ref_ptr <ClassC> _myElement;

    public:
        TextDrawCallback ( ClassC * element ) : _myElement ( element ) { }

        virtual void drawImplementation ( osg::RenderInfo& renderInfo, const osg::Drawable * drawable ) const
        {
             // if the flag is to true
             if ( _myElement->getNeedUpdate() )
             {
                  std::string newValue = anything computed
                  _myElement->getOsgText()->setText( newValue );
                  _myElement->setNeedUpdate( false ); // no need update anymore
             }

            drawable->drawImplementation ( renderInfo );
        }
    };


This works well under linux but make sometimes crashes under windows XP. The crash appear in the code called by
            drawable->drawImplementation ( renderInfo );
but i cant find out the main reason.

Did i something wrong with this callback ?

Thanks for your attention.
Regards,
Harold

Robert Osfield

unread,
Nov 20, 2009, 12:03:33 PM11/20/09
to OpenSceneGraph Users
Hi Harold,

The most likely issue is that you are running the view multi-threaded,
but not setting the DataVariance on the Text field to DYNAMIC - do
this and you'll prevent the next frame from advancing before it's
finished rendering the dynamically updated parts of the scene.

Robert.

> _______________________________________________
> osg-users mailing list
> osg-...@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
>
_______________________________________________
osg-users mailing list
osg-...@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Harold Comere

unread,
Nov 23, 2009, 3:09:25 AM11/23/09
to OpenSceneGraph Users
Hi Robert,

I used dynamic data variance and it seems to have fixed the issue, thank you.
Anyway i work with a single thread. But the text update is called by an event handler in MOVE event, maybe is it called too much in a short time ?

What does DYNAMIC data variance change ? Is it a kind of synchronization with mutex ?

Regards,
Harold

Robert Osfield

unread,
Nov 23, 2009, 4:15:28 AM11/23/09
to OpenSceneGraph Users

Have a search through the archives as I've answered this many times.

Robert.

Reply all
Reply to author
Forward
0 new messages