Praveena Sara wrote on 2012-07-27: 
> Hi
> 
> I'm drawing lines between two markers in osgart. So whenever they are
> moved, the lines are updated each time.
> 
> For this I'm updating an
> Code:
> osg::ref_ptr<osg::Vec3Array> points
> 
> 
> 
> My program crashes after it is run for a several seconds/minutes. I
found out
> that the following lines cause the issue (commenting those can avoid
it)
> 
> 
> Code:
> points->push_back(StartPoint);
> points->push_back(EndPoint);
> 
> 
> 
> I assume it is due to a memory leak, eventhough I use points->clear()
at
> the end.
> 
> Here's my code (please note that some lines have been omitted for
clarity)
> 
> 
> Code:
> class CallBackClass: public osg::NodeCallback{
> 
> private:
>       osg::ref_ptr<osg::Vec3Array> points;
>       osg::ref_ptr<osg::Geometry> beam;
> 
> public:
>       CallBackClass::CallBackClass(){
>               points = new osg::Vec3Array;
>               beam = new osg::Geometry;
>       }
> 
>       void CallBackClass::operator(){
>               //      osg::Vec3   StartPoint,
>               // osg::Vec3   EndPoint
> 
>               points->push_back(StartPoint);
points->push_back(EndPoint);
>               beam->setVertexArray(points.get());
>               beam->setColorArray(color.get());               beam-
>> setColorBinding(osg::Geometry::BIND_PER_PRIMITIVE);
>               beam->addPrimitiveSet(new
> osg::DrawArrays(GL_LINES,0,2));
>                 points->clear();
>       }
> }

What  threading mode are you using? Does it still crash if you are using
SingleThreaded mode?

OSG can do the cull traversal in a separate thread from the draw, so it
might be drawing the beam while you are modifying the points array. If
switching to SingleThreaded mode prevents the crash, this is the most
likely cause of your crash. I think you can set the DataVariance on the
Geometry to DYNAMIC to resolve the problem.

Hope this helps,
--
Bryan Thrall
Principal Software Engineer
FlightSafety International
[email protected]


_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to