Hi Peter,

If you are getting a crash then it's likely running the viewer
multi-threaded (the default if you are on a multi-core machine) so
that you are updating the text at the same time it's being used in the
draw traversal.  The way to resolve this is to do
text->setDataVariance(osg::Object::DYNAMIC); as this tells the draw
traversal that you plan to modify it the next frame is held back until
all the dynamic objects have been dispatched to OpenGL.

Robert.

On 12 June 2013 11:40, Peter Bako <osgfo...@tevs.eu> wrote:
> Hi,
>
> I have problems with changing text during rendering. I am trying to change 
> the text in the update callback of the text node, but sometimes I get a crash 
> (operator not incrementable) in the osg::osgText.
>
> Here is what I do in the update callback (Call the updateText() function on a 
> different object):
>
> Code:
>
>         void PiMeasurementGeomCallback::update( osg::NodeVisitor* nv, 
> osg::Drawable* geom){
>                  if(textDirty){
>                         textDirty = false;
>                         PiMeasurement* mes = 
> dynamic_cast<PiMeasurement*>(measurementGroup.get());
>                         if(!mes) return;
>                         mes->updateText();
>                 };
>         };
>
>
> and here is the updateText() function:
>
> Code:
> bool PiMeasurementLine::updateText(){
>                 double length = (_endPoint-_startPoint).length();
>                 length = 
> vectorAlongVector(PiSolidComponent::getv3(_movePlane),(_endPoint-_startPoint));
>                 if(length/2-(20*ratio) < 12*ratio){
>                         
> textGeom->setAlignment(osgText::TextBase::CENTER_BOTTOM );
>                 }else{
>                         
> textGeom->setAlignment(osgText::TextBase::CENTER_CENTER );
>                 }
>                 char s[20];
>                 sprintf(s,"%.2f",length);
>                 osgText::String str = osgText::String(s);
>                 textGeom->setText(str); ///////// if I comment out this, I 
> get no crash but I have to change the text anyhow
>
>                 
> textGeom->setPosition(PiSolidComponent::getv3(_movePlane)*(length/2));
>                 return true;
>         }
>
>
>
> The textGeom is actually the object where the update callback is attached(the 
> same as in "geom" parameter of the update function),
>
> What is the correct way to change the text of an osgText::Text geometry?
>
> Thank you!
>
> Cheers,
> Peter
>
> ------------------
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=54556#54556
>
>
>
>
>
> _______________________________________________
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to