Praveena Sara | 27 Jul 2012 15:30
Picon
Gravatar

Program crashes after running for a few seconds/mins--issue with push_back()

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; 
(Continue reading)

Thrall, Bryan | 27 Jul 2012 16:20
Favicon

Re: Program crashes after running for a fewseconds/mins--issue with push_back()

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)
(Continue reading)

Praveena Sara | 27 Jul 2012 17:14
Picon
Gravatar

Re: Program crashes after running for a few seconds/mins--issue with push_back()


> 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,

Making the viewer single threaded worked!

Code:
viewer.setThreadingModel(osgViewer::Viewer::SingleThreaded); 

Thanks a lot!
 :)

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=49091#49091

Thrall, Bryan | 27 Jul 2012 17:32
Favicon

Re: Program crashes after running for a fewseconds/mins--issue with push_back()

Praveena Sara wrote on 2012-07-27: 
> 
>> 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,
> 
> 
> Making the viewer single threaded worked!
> 
> 
> Code: viewer.setThreadingModel(osgViewer::Viewer::SingleThreaded);
> 
> 
> 
> Thanks a lot!
>  :)

Glad I could help :)

Did setting the DataVariance on the Geometry to DYNAMIC (but keeping the
default threading model) work? That would be a better solution because
you still get the benefits of parallel cull and draw for everything in
the scene that is not DYNAMIC.

--
Bryan Thrall
Principal Software Engineer
FlightSafety International
(Continue reading)

Praveena Sara | 27 Jul 2012 17:53
Picon
Gravatar

Re: Program crashes after running for a few seconds/mins--issue with push_back()

Yes, both methods worked. great! thanks

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=49093#49093

Ulrich Hertlein | 28 Jul 2012 10:11
Picon
Favicon

Re: Program crashes after running for a few seconds/mins--issue with push_back()

Hi Praveena,

On 27/07/12 23:30 , Praveena Sara wrote:
> I'm drawing lines between two markers in osgart. So whenever they are moved, the lines are updated each time.
>... 
> 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)
>...
> I assume it is due to a memory leak, eventhough I use points->clear() at the end.
> 
> 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()); 
(Continue reading)


Gmane