Skip to content

Commit

Permalink
From Colin McDonald and Robert Osfield, converted Traits::sharedConte…
Browse files Browse the repository at this point in the history
…xt from GraphicsContext* to osg:observer_ptr<GraphicsContext> to prevent dangling pointer issues.
  • Loading branch information
robertosfield committed Sep 5, 2012
1 parent 63444f6 commit 39dcea9
Show file tree
Hide file tree
Showing 19 changed files with 25 additions and 25 deletions.
2 changes: 1 addition & 1 deletion examples/osgviewerFOX/FOX_OSG.cpp
Expand Up @@ -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() );
Expand Down
2 changes: 1 addition & 1 deletion examples/osgviewerWX/osgviewerWX.cpp
Expand Up @@ -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() );
Expand Down
2 changes: 1 addition & 1 deletion include/osg/GraphicsContext
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion include/osgViewer/GraphicsWindow
Expand Up @@ -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() );
Expand Down
2 changes: 1 addition & 1 deletion include/osgViewer/api/Carbon/GraphicsWindowCarbon
Expand Up @@ -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() );
Expand Down
2 changes: 1 addition & 1 deletion include/osgViewer/api/Carbon/PixelBufferCarbon
Expand Up @@ -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() );
Expand Down
2 changes: 1 addition & 1 deletion include/osgViewer/api/Cocoa/GraphicsWindowCocoa
Expand Up @@ -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() );
Expand Down
2 changes: 1 addition & 1 deletion include/osgViewer/api/Cocoa/PixelBufferCocoa
Expand Up @@ -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() );
Expand Down
2 changes: 1 addition & 1 deletion include/osgViewer/api/IOS/GraphicsWindowIOS
Expand Up @@ -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() );
Expand Down
2 changes: 1 addition & 1 deletion include/osgViewer/api/X11/GraphicsWindowX11
Expand Up @@ -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() );
Expand Down
4 changes: 2 additions & 2 deletions src/osgQt/GraphicsWindowQt.cpp
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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() );
Expand Down
2 changes: 1 addition & 1 deletion src/osgViewer/GraphicsWindowCarbon.cpp
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/osgViewer/GraphicsWindowCocoa.mm
Expand Up @@ -1186,7 +1186,7 @@ virtual void getWindowBounds(CGRect& rect)
// 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();
Expand Down
6 changes: 3 additions & 3 deletions src/osgViewer/GraphicsWindowWin32.cpp
Expand Up @@ -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() );
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()))
Expand Down
2 changes: 1 addition & 1 deletion src/osgViewer/GraphicsWindowX11.cpp
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/osgViewer/PixelBufferCarbon.cpp
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/osgViewer/PixelBufferCocoa.mm
Expand Up @@ -63,7 +63,7 @@
// 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();
Expand Down
6 changes: 3 additions & 3 deletions src/osgViewer/PixelBufferWin32.cpp
Expand Up @@ -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() );
Expand Down Expand Up @@ -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) )
Expand Down
4 changes: 2 additions & 2 deletions src/osgViewer/PixelBufferX11.cpp
Expand Up @@ -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() );
Expand Down Expand Up @@ -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 );
Expand Down

0 comments on commit 39dcea9

Please sign in to comment.