From 727e55a63af118f85a00607803f13fa864d103c5 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 31 Aug 2005 20:39:05 +0000 Subject: [PATCH] Removed circular reference of osg::CameraNode, fixing memory leak. Added a auto exit after a maximum number of frames are completed. --- examples/osgcamera/GNUmakefile | 2 +- examples/osgcamera/osgcamera.cpp | 21 ++++++++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/examples/osgcamera/GNUmakefile b/examples/osgcamera/GNUmakefile index 970a7ca6a..745fae01d 100644 --- a/examples/osgcamera/GNUmakefile +++ b/examples/osgcamera/GNUmakefile @@ -4,7 +4,7 @@ include $(TOPDIR)/Make/makedefs CXXFILES =\ osgcamera.cpp\ -LIBS += -losgProducer -lProducer -losgDB -losgUtil -losg $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS) -lOpenThreads +LIBS += -losgDB -losgUtil -losg $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS) -lOpenThreads INSTFILES = \ $(CXXFILES)\ diff --git a/examples/osgcamera/osgcamera.cpp b/examples/osgcamera/osgcamera.cpp index fe2ab21c4..4ff9d3f5c 100644 --- a/examples/osgcamera/osgcamera.cpp +++ b/examples/osgcamera/osgcamera.cpp @@ -13,6 +13,8 @@ #include #include +#include +#include #include #include @@ -73,7 +75,7 @@ struct CullOperation : public osg::GraphicsThread::Operation _sceneView->cull(); } - osg::ref_ptr _camera; + osg::CameraNode* _camera; osg::ref_ptr _sceneView; }; @@ -118,12 +120,18 @@ struct DrawOperation : public osg::GraphicsThread::Operation // int main( int argc, char **argv ) { + if (argc<2) { std::cout << argv[0] <<": requires filename argument." << std::endl; return 1; } + // load the osgProducer library manually. + osg::ref_ptr osgProducerLib = + osgDB::DynamicLibrary::loadLibrary(osgDB::Registry::instance()->createLibraryNameForNodeKit("osgProducer")); + + // load the scene. osg::ref_ptr loadedModel = osgDB::readNodeFile(argv[1]); if (!loadedModel) @@ -300,10 +308,11 @@ int main( int argc, char **argv ) osg::Timer_t start_tick = osg::Timer::instance()->tick(); osg::Timer_t previous_tick = start_tick; - bool done = false; + bool done = false; + unsigned int maxNumFrames = 500; // main loop - update scene graph, dispatch frame, wait for frame done. - while( !done ) + while( !done && frameNumtick(); @@ -334,5 +343,11 @@ int main( int argc, char **argv ) } } + + // delete the cameras, associated contexts and threads. + cameraList.clear(); + + std::cout<<"Exiting application"<