From Colin McDonald and Robert Osfield, converted Traits::sharedContext from GraphicsContext* to osg:observer_ptr<GraphicsContext> to prevent dangling pointer issues.

This commit is contained in:
Robert Osfield 2012-09-05 21:03:41 +00:00
parent 63444f648f
commit 39dcea9ebb
19 changed files with 25 additions and 25 deletions

View File

@ -48,7 +48,7 @@ void GraphicsWindowFOX::init()
setState( new osg::State );
getState()->setGraphicsContext(this);
if (_traits.valid() && _traits->sharedContext)
if (_traits.valid() && _traits->sharedContext.valid())
{
getState()->setContextID( _traits->sharedContext->getState()->getContextID() );
incrementContextIDUsageCount( getState()->getContextID() );

View File

@ -299,7 +299,7 @@ void GraphicsWindowWX::init()
setState( new osg::State );
getState()->setGraphicsContext(this);
if (_traits.valid() && _traits->sharedContext)
if (_traits.valid() && _traits->sharedContext.valid())
{
getState()->setContextID( _traits->sharedContext->getState()->getContextID() );
incrementContextIDUsageCount( getState()->getContextID() );

View File

@ -128,7 +128,7 @@ class OSG_EXPORT GraphicsContext : public Object
bool getContextVersion(unsigned int& major, unsigned int& minor) const;
// shared context
GraphicsContext* sharedContext;
osg::observer_ptr<GraphicsContext> sharedContext;
osg::ref_ptr<osg::Referenced> inheritedWindowData;

View File

@ -247,7 +247,7 @@ class GraphicsWindowEmbedded : public GraphicsWindow
setState( new osg::State );
getState()->setGraphicsContext(this);
if (_traits.valid() && _traits->sharedContext)
if (_traits.valid() && _traits->sharedContext.valid())
{
getState()->setContextID( _traits->sharedContext->getState()->getContextID() );
incrementContextIDUsageCount( getState()->getContextID() );

View File

@ -48,7 +48,7 @@ class GraphicsWindowCarbon : public osgViewer::GraphicsWindow, public osgViewer:
setState( new osg::State );
getState()->setGraphicsContext(this);
if (_traits.valid() && _traits->sharedContext)
if (_traits.valid() && _traits->sharedContext.valid())
{
getState()->setContextID( _traits->sharedContext->getState()->getContextID() );
incrementContextIDUsageCount( getState()->getContextID() );

View File

@ -45,7 +45,7 @@ class OSGVIEWER_EXPORT PixelBufferCarbon : public osg::GraphicsContext, public o
setState( new osg::State );
getState()->setGraphicsContext(this);
if (_traits.valid() && _traits->sharedContext)
if (_traits.valid() && _traits->sharedContext.valid())
{
getState()->setContextID( _traits->sharedContext->getState()->getContextID() );
incrementContextIDUsageCount( getState()->getContextID() );

View File

@ -76,7 +76,7 @@ class GraphicsWindowCocoa : public osgViewer::GraphicsWindow, public osgViewer::
setState( new osg::State );
getState()->setGraphicsContext(this);
if (_traits.valid() && _traits->sharedContext)
if (_traits.valid() && _traits->sharedContext.valid())
{
getState()->setContextID( _traits->sharedContext->getState()->getContextID() );
incrementContextIDUsageCount( getState()->getContextID() );

View File

@ -47,7 +47,7 @@ class OSGVIEWER_EXPORT PixelBufferCocoa : public osg::GraphicsContext, public os
setState( new osg::State );
getState()->setGraphicsContext(this);
if (_traits.valid() && _traits->sharedContext)
if (_traits.valid() && _traits->sharedContext.valid())
{
getState()->setContextID( _traits->sharedContext->getState()->getContextID() );
incrementContextIDUsageCount( getState()->getContextID() );

View File

@ -72,7 +72,7 @@ class GraphicsWindowIOS : public osgViewer::GraphicsWindow
setState( new osg::State );
getState()->setGraphicsContext(this);
if (_traits.valid() && _traits->sharedContext)
if (_traits.valid() && _traits->sharedContext.valid())
{
getState()->setContextID( _traits->sharedContext->getState()->getContextID() );
incrementContextIDUsageCount( getState()->getContextID() );

View File

@ -59,7 +59,7 @@ class OSGVIEWER_EXPORT GraphicsWindowX11 : public osgViewer::GraphicsWindow, pub
setState( new osg::State );
getState()->setGraphicsContext(this);
if (_traits.valid() && _traits->sharedContext)
if (_traits.valid() && _traits->sharedContext.valid())
{
getState()->setContextID( _traits->sharedContext->getState()->getContextID() );
incrementContextIDUsageCount( getState()->getContextID() );

View File

@ -382,7 +382,7 @@ bool GraphicsWindowQt::init( QWidget* parent, const QGLWidget* shareWidget, Qt::
{
// shareWidget
if ( !shareWidget ) {
GraphicsWindowQt* sharedContextQt = dynamic_cast<GraphicsWindowQt*>(_traits->sharedContext);
GraphicsWindowQt* sharedContextQt = dynamic_cast<GraphicsWindowQt*>(_traits->sharedContext.get());
if ( sharedContextQt )
shareWidget = sharedContextQt->getGLWidget();
}
@ -422,7 +422,7 @@ bool GraphicsWindowQt::init( QWidget* parent, const QGLWidget* shareWidget, Qt::
getState()->setGraphicsContext(this);
// initialize contextID
if ( _traits.valid() && _traits->sharedContext )
if ( _traits.valid() && _traits->sharedContext.valid() )
{
getState()->setContextID( _traits->sharedContext->getState()->getContextID() );
incrementContextIDUsageCount( getState()->getContextID() );

View File

@ -399,7 +399,7 @@ bool GraphicsWindowCarbon::realizeImplementation()
// create the context
AGLContext sharedContextCarbon = NULL;
GraphicsHandleCarbon* graphicsHandleCarbon = dynamic_cast<GraphicsHandleCarbon*>(_traits->sharedContext);
GraphicsHandleCarbon* graphicsHandleCarbon = dynamic_cast<GraphicsHandleCarbon*>(_traits->sharedContext.get());
if (graphicsHandleCarbon)
{
sharedContextCarbon = graphicsHandleCarbon->getAGLContext();

View File

@ -1186,7 +1186,7 @@ bool GraphicsWindowCocoa::realizeImplementation()
// create the context
NSOpenGLContext* sharedContext = NULL;
GraphicsHandleCocoa* graphicsHandleCocoa = dynamic_cast<GraphicsHandleCocoa*>(_traits->sharedContext);
GraphicsHandleCocoa* graphicsHandleCocoa = dynamic_cast<GraphicsHandleCocoa*>(_traits->sharedContext.get());
if (graphicsHandleCocoa)
{
sharedContext = graphicsHandleCocoa->getNSOpenGLContext();

View File

@ -1150,7 +1150,7 @@ GraphicsWindowWin32::GraphicsWindowWin32( osg::GraphicsContext::Traits* traits )
setState( new osg::State );
getState()->setGraphicsContext(this);
if (_traits.valid() && _traits->sharedContext)
if (_traits.valid() && _traits->sharedContext.valid())
{
getState()->setContextID( _traits->sharedContext->getState()->getContextID() );
incrementContextIDUsageCount( getState()->getContextID() );
@ -1903,7 +1903,7 @@ bool GraphicsWindowWin32::realizeImplementation()
if (!_initialized) return false;
}
if (_traits.valid() && (_traits->sharedContext || _traits->vsync || _traits->swapGroupEnabled))
if (_traits.valid() && (_traits->sharedContext.valid() || _traits->vsync || _traits->swapGroupEnabled))
{
// make context current so we can test capabilities and set up context sharing
struct RestoreContext
@ -1932,7 +1932,7 @@ bool GraphicsWindowWin32::realizeImplementation()
}
// set up sharing of contexts if required
GraphicsHandleWin32* graphicsHandleWin32 = dynamic_cast<GraphicsHandleWin32*>(_traits->sharedContext);
GraphicsHandleWin32* graphicsHandleWin32 = dynamic_cast<GraphicsHandleWin32*>(_traits->sharedContext.get());
if (graphicsHandleWin32)
{
if (!wglShareLists(graphicsHandleWin32->getWGLContext(), getWGLContext()))

View File

@ -717,7 +717,7 @@ void GraphicsWindowX11::init()
}
// get any shared GLX contexts
GraphicsHandleX11* graphicsHandleX11 = dynamic_cast<GraphicsHandleX11*>(_traits->sharedContext);
GraphicsHandleX11* graphicsHandleX11 = dynamic_cast<GraphicsHandleX11*>(_traits->sharedContext.get());
Context sharedContext = graphicsHandleX11 ? graphicsHandleX11->getContext() : 0;
#ifdef OSG_USE_EGL

View File

@ -81,7 +81,7 @@ bool PixelBufferCarbon::realizeImplementation()
AGLContext sharedContext = NULL;
// get any shared AGL contexts
GraphicsHandleCarbon* graphicsHandleCarbon = dynamic_cast<GraphicsHandleCarbon*>(_traits->sharedContext);
GraphicsHandleCarbon* graphicsHandleCarbon = dynamic_cast<GraphicsHandleCarbon*>(_traits->sharedContext.get());
if (graphicsHandleCarbon)
{
sharedContext = graphicsHandleCarbon->getAGLContext();

View File

@ -63,7 +63,7 @@ bool PixelBufferCocoa::realizeImplementation()
// create the context
NSOpenGLContext* sharedContext = NULL;
GraphicsHandleCocoa* graphicsHandleCocoa = dynamic_cast<GraphicsHandleCocoa*>(_traits->sharedContext);
GraphicsHandleCocoa* graphicsHandleCocoa = dynamic_cast<GraphicsHandleCocoa*>(_traits->sharedContext.get());
if (graphicsHandleCocoa)
{
sharedContext = graphicsHandleCocoa->getNSOpenGLContext();

View File

@ -463,7 +463,7 @@ PixelBufferWin32::PixelBufferWin32( osg::GraphicsContext::Traits* traits ):
setState( new osg::State );
getState()->setGraphicsContext( this );
if (_traits.valid() && _traits->sharedContext )
if (_traits.valid() && _traits->sharedContext.valid() )
{
getState()->setContextID( _traits->sharedContext->getState()->getContextID() );
incrementContextIDUsageCount( getState()->getContextID() );
@ -658,9 +658,9 @@ bool PixelBufferWin32::realizeImplementation()
if (!_initialized) return false;
if ( _traits->sharedContext )
if ( _traits->sharedContext.valid() )
{
GraphicsHandleWin32* graphicsHandleWin32 = dynamic_cast<GraphicsHandleWin32*>(_traits->sharedContext);
GraphicsHandleWin32* graphicsHandleWin32 = dynamic_cast<GraphicsHandleWin32*>(_traits->sharedContext.get());
if (graphicsHandleWin32)
{
if ( !wglShareLists(graphicsHandleWin32->getWGLContext(), _hglrc) )

View File

@ -43,7 +43,7 @@ PixelBufferX11::PixelBufferX11(osg::GraphicsContext::Traits* traits)
setState( new osg::State );
getState()->setGraphicsContext(this);
if (_traits.valid() && _traits->sharedContext)
if (_traits.valid() && _traits->sharedContext.valid())
{
getState()->setContextID( _traits->sharedContext->getState()->getContextID() );
incrementContextIDUsageCount( getState()->getContextID() );
@ -216,7 +216,7 @@ void PixelBufferX11::init()
}
// get any shared GLX contexts
GraphicsHandleX11* graphicsHandleX11 = dynamic_cast<GraphicsHandleX11*>(_traits->sharedContext);
GraphicsHandleX11* graphicsHandleX11 = dynamic_cast<GraphicsHandleX11*>(_traits->sharedContext.get());
Context sharedContext = graphicsHandleX11 ? graphicsHandleX11->getContext() : 0;
_context = glXCreateContext( _display, _visualInfo, sharedContext, True );