Hi Joshua,

I hacked a fix into the code and found that it works quite well if there is a 
mutex locker blocking anything that might change the text in osgText.cpp.

This has been discussed a lot in the past. You can't just run threads that will go call stuff in OSG at any time. You need to modify most things during the update traversal (which is essentially what your mutex ensures). This is indeed a hack.

What I would suggest instead, to prevent threads waiting for one another and to prevent you setting the text on your osgText object multiple times between two frames (which can be expensive in my experience, for something the user will never see) is to have a simple buffering scheme.

1. Your thread can put the text values you want to display in some holding area (which you would lock to ensure writing to it is threadsafe). 2. An update callback on your osgText object would go get the latest value in your holding area, compare it with the last value that was set, and only if it's different will set it on the osgText object.

Your osgText object still has to have DYNAMIC data variance, so that the viewer knows to hold back the next frame until that object's update is done. But the advantage of the above suggestion is really that two threads won't wait for each other, they will really hold the mutex (for your holding area) a minimum of time. Plus it's less intrusive on your main loop - you can encapsulate all that in a simple class, and if you need to add more text objects later, you don't need to add other mutexes or modify your main loop in any way.

Hope this helps,

J-S
--
______________________________________________________
Jean-Sebastien Guay    jean-sebastien.g...@cm-labs.com
                               http://www.cm-labs.com/
                    http://whitestar02.dyndns-web.com/
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to