Hi Andreas,
late response, but I just got into it right now:
Andreas Zieringer wrote:
Hi Antonio,
Hi,
just a quick question, why is this code leaking
memory:
while( true ){
beginEditCP(m_pFBO, FBOViewport::CameraFieldMask);
m_pFBO->setCamera(PerspectiveCamera::create());
endEditCP(m_pFBO, FBOViewport::CameraFieldMask);
}
???
Shouldn't the setCamera method destroy implicitly the old
camera set on the viewport (he should hold the last
reference to the old camera!)
yes, try this: Thread::getCurrent()->getChangeList()->clearAll();
It doesn't work as I expect it to work. I attached a modified
version of the first tutorial. In each render loop it creates
some osg instances. When you press <esc> it prints a list of
non deallocated instances. All instances created in the loop
are still alive. Only calling explicitly subRefCP frees the
memory. Doing something like:
PassiveBackgroundPtr pw;
while( true )
pw = PassiveBackground::create();
leads to memory leaks. Also calling getChangeList()->clearAll()
doesn't help much. Is this behaviour by design?
Regards,
Toni
--
Ing. Antonio Bleile
Seac02 S.r.l.
via Avogadro 4
10121 Torino Italia
Tel. +39.011.197.006.52
Fax +39.011.197.006.53
E-mail [EMAIL PROTECTED]
Sito www.seac02.it
// OpenSG Tutorial Example: Hello World
//
// Minimalistic OpenSG program
//
// This is the shortest useful OpenSG program
// (if you remove all the comments ;)
//
// It shows how to use OpenSG together with GLUT to create a little
// interactive scene viewer.
//
// GLUT is used for window handling
#include <OpenSG/OSGGLUT.h>
// General OpenSG configuration, needed everywhere
#include <OpenSG/OSGConfig.h>
// Methods to create simple geometry: boxes, spheres, tori etc.
#include <OpenSG/OSGSimpleGeometry.h>
// The GLUT-OpenSG connection class
#include <OpenSG/OSGGLUTWindow.h>
// A little helper to simplify scene management and interaction
#include <OpenSG/OSGSimpleSceneManager.h>
#include <OpenSG/OSGPassiveBackground.h>
#include <OpenSG/OSGPerspectiveCamera.h>
#include <OpenSG/OSGViewport.h>
// Activate the OpenSG namespace
// This is not strictly necessary, you can also prefix all OpenSG symbols
// with OSG::, but that would be a bit tedious for this example
OSG_USING_NAMESPACE
// The SimpleSceneManager to manage simple applications
SimpleSceneManager *mgr;
// forward declaration so we can have the interesting stuff upfront
int setupGLUT( int *argc, char *argv[] );
PassiveBackgroundPtr dummyPB;
NodePtr dummyNode;
ViewportPtr dummyVP;
UInt32 fcStoreSize;
void printOSGInstances()
{
const std::vector<FieldContainerPtr> &fcs =
*FieldContainerFactory::the()->getFieldContainerStore();
int notNull = 0;
for(int i=fcStoreSize;i<fcs.size();++i)
{
FieldContainerPtr fc = fcs[i];
if(fc != NullFC)
{
notNull++;
printf( "Detected living FC %s!\n", fc->getTypeName());
}
}
printf( "%d out of %d FC's are not destroyed\n", notNull,
fcs.size()-fcStoreSize );
}
// Initialize GLUT & OpenSG and set up the scene
int main(int argc, char **argv)
{
// OSG init
osgInit(argc,argv);
fcStoreSize =
FieldContainerFactory::the()->getFieldContainerStore()->size();
// GLUT init
int winid = setupGLUT(&argc, argv);
// the connection between GLUT and OpenSG
GLUTWindowPtr gwin= GLUTWindow::create();
gwin->setId(winid);
gwin->init();
// create the scene
NodePtr scene = makeTorus(.5, 2, 16, 16);
dummyVP = Viewport::create();
// create the SimpleSceneManager helper
mgr = new SimpleSceneManager;
// tell the manager what to manage
mgr->setWindow(gwin );
mgr->setRoot (scene);
// show the whole scene
mgr->showAll();
// GLUT main loop
glutMainLoop();
return 0;
}
//
// GLUT callback functions
//
// redraw the window
void display(void)
{
dummyPB = PassiveBackground::create();
dummyNode = Node::create();
beginEditCP(dummyVP, Viewport::CameraFieldMask);
dummyVP->setCamera(PerspectiveCamera::create());
endEditCP(dummyVP, Viewport::CameraFieldMask);
Thread::getCurrent()->getChangeList()->clearAll();
// usign subref works ok!
//subRefCP( dummyPB );
//subRefCP( dummyNode );
mgr->setRoot (makeTorus(.5, 2, 16, 16));
mgr->redraw();
Thread::getCurrent()->getChangeList()->clearAll();
}
// react to size changes
void reshape(int w, int h)
{
mgr->resize(w, h);
glutPostRedisplay();
}
// react to mouse button presses
void mouse(int button, int state, int x, int y)
{
if (state)
mgr->mouseButtonRelease(button, x, y);
else
mgr->mouseButtonPress(button, x, y);
glutPostRedisplay();
}
// react to mouse motions with pressed buttons
void motion(int x, int y)
{
mgr->mouseMove(x, y);
glutPostRedisplay();
}
// react to keys
void keyboard(unsigned char k, int x, int y)
{
switch(k)
{
case 27:
{
delete mgr;
Thread::getCurrent()->getChangeList()->clearAll();
OSG::osgExit();
printOSGInstances();
Sleep(10000);
exit(0);
}
break;
}
}
// setup the GLUT library which handles the windows for us
int setupGLUT(int *argc, char *argv[])
{
glutInit(argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
int winid = glutCreateWindow("OpenSG");
glutReshapeFunc(reshape);
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutKeyboardFunc(keyboard);
return winid;
}
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users