Improvements to osgProducer lib, in particular adding a mutex lock to the init() call in

SceneView to prevent init running multi-threaded.
This commit is contained in:
Robert Osfield
2003-01-20 20:33:50 +00:00
parent 4de63e72c6
commit dc83e399a9
2 changed files with 37 additions and 0 deletions

View File

@@ -18,6 +18,9 @@ class OSGPRODUCER_EXPORT SceneHandler : public Producer::Camera::SceneHandler, p
SceneHandler( osg::DisplaySettings *ds = NULL);
/// override the init method to force it be run one at a time.
virtual void init();
void cull(Producer::Camera &cam);
void draw(Producer::Camera &);

View File

@@ -3,6 +3,7 @@
//as published by the Free Software Foundation.
#include <osgProducer/SceneHandler>
#include <Producer/Mutex>
using namespace osgUtil;
using namespace osgProducer;
@@ -14,8 +15,28 @@ SceneHandler::SceneHandler( osg::DisplaySettings *ds = NULL) :
pm = new osg::RefMatrix;
}
void SceneHandler::init()
{
static Producer::Mutex mutex;
osg::notify(osg::INFO)<<"entering "<<this<<" init."<<std::endl;
mutex.lock();
osg::notify(osg::INFO)<<" running "<<this<<" init."<<std::endl;
SceneView::init();
osg::notify(osg::INFO)<<" done "<<this<<" init."<<std::endl;
mutex.unlock();
osg::notify(osg::INFO)<<" unlocked "<<this<<" init."<<std::endl;
}
void SceneHandler::cull(Producer::Camera &cam)
{
// static Producer::Mutex mutex;
// osg::notify(osg::INFO)<<"entering "<<this<<" cull."<<std::endl;
// mutex.lock();
// osg::notify(osg::INFO)<<" running "<<this<<" cull."<<std::endl;
pm->set(cam.getProjectionMatrix());
mm->set(cam.getPositionAndAttitudeMatrix());
setProjectionMatrix( pm.get() );
@@ -28,11 +49,24 @@ void SceneHandler::cull(Producer::Camera &cam)
setViewport( x, y, w, h );
SceneView::cull();
// osg::notify(osg::INFO)<<" done "<<this<<" cull."<<std::endl;
// mutex.unlock();
// osg::notify(osg::INFO)<<" unlocked "<<this<<" cull."<<std::endl;
}
void SceneHandler::draw(Producer::Camera &)
{
// static Producer::Mutex mutex;
// osg::notify(osg::INFO)<<"entering "<<this<<" draw."<<std::endl;
// mutex.lock();
// osg::notify(osg::INFO)<<" running "<<this<<" draw."<<std::endl;
//
SceneView::draw();
// osg::notify(osg::INFO)<<" done "<<this<<" draw."<<std::endl;
// mutex.unlock();
// osg::notify(osg::INFO)<<" unlocked "<<this<<" draw."<<std::endl;
}
void SceneHandler::setContextID( int id )