Re: [osg-users] seg fault with text->setText(mystring) called in NodeCallback
If you're developing on Windows under visual studio one thing you should check is that all libraries are linked with the same runtime. I have seen weird segfaults using std::string when linking debug binaries with binaries built using release mode. Apparently Microsofts debug and release runtimes have different implementations of std::string leading to misalignment and overflow when passing strings between modules. Regards, Phil On 12/01/2013, at 12:44 AM, DavidHornung wrote: > Hi Robert, > > i have tested you tip, but it in my case it seems not to work. > I only call the setText() method via my NodeVisitor, also run the viewer in > SingleThreaded mode, and set text->setDataVariance(osg::Object::DYNAMIC). > what else could be wrong? > > David >> Hi David, >> >> Best guess would be that you are running the viewer multi-threaded >> (it's default if you have a multicore processor) and the update >> traversal to the text is occurring at the same time as the draw >> traversal that is reading. The solution is to tell the scene graph >> that you plan to dynamically update the text object so that it knows >> not to overlap the update/event and draw traversals. You can do this >> by using text->setDataVariance(osg::Object::DYNAMIC); >> >> Robert. >> >> On 10 January 2013 16:41, DavidHornung wrote: >>> Hello, >>> i have a seg fault because the osgText::Text::setText(std::string) is not >>> thread-save. >>> It appears from type to time >>> >>> Why get I this seg fault sometimes? >>> >>> I have the following setup >>> >>> class ObjectGroup : public osg::Group >>> { >>> ... >>>ObjectGroup() >>> { >>>... >>>text = osgText::Text; >>> >>>this->addChild(text); >>>this->setUpdateCallback(new ObjectNodeCallback); >>> } >>> >>> //called from NodeCallback >>> void updateText() >>> { >>> text->setText(myText); >>>} >>> >>> private: >>>osgText::Text text; >>>std::String myText; >>> ... >>> }; >>> >>> class ObjectNodeCallback : public osg::NodeCallback >>> { >>> //override >>> operator ()(osg::Node* node, osg::NodeVisitor* nv) >>> { >>> osg::ref_ptr obj = >>> dynamic_cast(node); >>> obj->updateText(); >>> traverse(node, nv); >>> } >>> }; >>> >>> >>> Cheers, >>> David >>> ___ >>> 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 > > ___ > 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
Re: [osg-users] seg fault with text->setText(mystring) called in NodeCallback
On 11 January 2013 11:44, DavidHornung wrote: > Hi Robert, > > i have tested you tip, but it in my case it seems not to work. > I only call the setText() method via my NodeVisitor, also run the viewer in > SingleThreaded mode, and set text->setDataVariance(osg::Object::DYNAMIC). > what else could be wrong? Again I can only guess - it's you who has the seg fault and the ability to debug it, best guess now is a dangling pointer? Try using ref_ptr<> rather than C pointers. Robert. ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] seg fault with text->setText(mystring) called in NodeCallback
Hi Robert, i have tested you tip, but it in my case it seems not to work. I only call the setText() method via my NodeVisitor, also run the viewer in SingleThreaded mode, and set text->setDataVariance(osg::Object::DYNAMIC). what else could be wrong? David Hi David, Best guess would be that you are running the viewer multi-threaded (it's default if you have a multicore processor) and the update traversal to the text is occurring at the same time as the draw traversal that is reading. The solution is to tell the scene graph that you plan to dynamically update the text object so that it knows not to overlap the update/event and draw traversals. You can do this by using text->setDataVariance(osg::Object::DYNAMIC); Robert. On 10 January 2013 16:41, DavidHornung wrote: Hello, i have a seg fault because the osgText::Text::setText(std::string) is not thread-save. It appears from type to time Why get I this seg fault sometimes? I have the following setup class ObjectGroup : public osg::Group { ... ObjectGroup() { ... text = osgText::Text; this->addChild(text); this->setUpdateCallback(new ObjectNodeCallback); } //called from NodeCallback void updateText() { text->setText(myText); } private: osgText::Text text; std::String myText; ... }; class ObjectNodeCallback : public osg::NodeCallback { //override operator ()(osg::Node* node, osg::NodeVisitor* nv) { osg::ref_ptr obj = dynamic_cast(node); obj->updateText(); traverse(node, nv); } }; Cheers, David ___ 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 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] seg fault with text->setText(mystring) called in NodeCallback
Hi David, Best guess would be that you are running the viewer multi-threaded (it's default if you have a multicore processor) and the update traversal to the text is occurring at the same time as the draw traversal that is reading. The solution is to tell the scene graph that you plan to dynamically update the text object so that it knows not to overlap the update/event and draw traversals. You can do this by using text->setDataVariance(osg::Object::DYNAMIC); Robert. On 10 January 2013 16:41, DavidHornung wrote: > Hello, > i have a seg fault because the osgText::Text::setText(std::string) is not > thread-save. > It appears from type to time > > Why get I this seg fault sometimes? > > I have the following setup > > class ObjectGroup : public osg::Group > { > ... > ObjectGroup() >{ > ... > text = osgText::Text; > > this->addChild(text); > this->setUpdateCallback(new ObjectNodeCallback); >} > > //called from NodeCallback >void updateText() >{ > text->setText(myText); > } > > private: > osgText::Text text; > std::String myText; > ... > }; > > class ObjectNodeCallback : public osg::NodeCallback > { > //override > operator ()(osg::Node* node, osg::NodeVisitor* nv) > { > osg::ref_ptr obj = > dynamic_cast(node); > obj->updateText(); > traverse(node, nv); > } > }; > > > Cheers, > David > ___ > 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
[osg-users] seg fault with text->setText(mystring) called in NodeCallback
Hello, i have a seg fault because the osgText::Text::setText(std::string) is not thread-save. It appears from type to time Why get I this seg fault sometimes? I have the following setup class ObjectGroup : public osg::Group { ... ObjectGroup() { ... text = osgText::Text; this->addChild(text); this->setUpdateCallback(new ObjectNodeCallback); } //called from NodeCallback void updateText() { text->setText(myText); } private: osgText::Text text; std::String myText; ... }; class ObjectNodeCallback : public osg::NodeCallback { //override operator ()(osg::Node* node, osg::NodeVisitor* nv) { osg::ref_ptr obj = dynamic_cast(node); obj->updateText(); traverse(node, nv); } }; Cheers, David ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org