Re: [osg-users] Stack overflow error with derived osg classes

2012-03-14 Thread Alberto Luaces
Hi Antony,

Antony Tomarelli writes:

   root-addChild(t);
   geode-setUserData(t);

You have a circular dependency there. Nodes Test an Geode point to each
other. At initialization time, the initialization of one triggers the
initialization of the other, and so on. This causes the stack overflow.

You can avoid that dependency since any osg::Node can retrieve is parent
node through getParent() or getParents() — that way, your user data
field is not needed anymore.

-- 
Alberto

___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


[osg-users] Stack overflow error with derived osg classes

2012-03-13 Thread Antony Tomarelli
(Sorry, couldn't figure out how to be specific but concise with the title)

I created a class (called Test) that derived from PositionAttitudeTransform 
which would control the position of a shape (so a geode) in the scene. I wanted 
to then update it by setting that class as the geode's user data, and then 
having it update via a callback (which is irrelevant to the problem (as far as 
I can see)).

However, when I add an instance of Test as geode's user data a stack overflow 
occurs when the viewer calls realize(). No stack overflow if I don't. I see 
that addChild() is virtual, but I don't know if that would cause problems - I'm 
still rather a novice to OSG and C++. Can anyone explain the problem?

Here's the code for Test:


Code:

#include osg/PositionAttitudeTransform

class Test : public osg::PositionAttitudeTransform
{
public:
Test(osg::ref_ptrosg::Node geode) { addChild(geode); }
~Test() { }

};




And here's main:


Code:

int main(int argc, const char** argv)
{
osg::ref_ptrosg::Group root = new osg::Group();

// Create viewer
osgViewer::Viewer viewer;
viewer.setSceneData(root);

osg::ref_ptrosg::Geode geode = new osg::Geode();

Test* t = new Test(geode);

root-addChild(t);
geode-setUserData(t);

// Create camera
viewer.setCameraManipulator(new osgGA::TrackballManipulator());

// Run scene
viewer.setUpViewInWindow(0, 0, 800, 600);
viewer.realize();

while (!viewer.done())
{
// Step the graphics display
viewer.frame();
}

return 0;
}




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





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Stack overflow error with derived osg classes

2012-03-13 Thread Jason Daly

On 03/02/2012 02:32 PM, Antony Tomarelli wrote:

(Sorry, couldn't figure out how to be specific but concise with the title)

I created a class (called Test) that derived from PositionAttitudeTransform 
which would control the position of a shape (so a geode) in the scene. I wanted 
to then update it by setting that class as the geode's user data, and then 
having it update via a callback (which is irrelevant to the problem (as far as 
I can see)).

However, when I add an instance of Test as geode's user data a stack overflow 
occurs when the viewer calls realize(). No stack overflow if I don't. I see 
that addChild() is virtual, but I don't know if that would cause problems - I'm 
still rather a novice to OSG and C++. Can anyone explain the problem?


A stack overflow usually means some kind of infinite recursion is 
happening.  A method is calling another method, which calls another 
method, and so forth, until eventually the original method is called 
again.  This cycle continues forever until the system runs out of stack 
space (there's no more room to keep track of all the method calls).


--J
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org