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:
parent
63444f648f
commit
39dcea9ebb
@ -48,7 +48,7 @@ void GraphicsWindowFOX::init()
|
|||||||
setState( new osg::State );
|
setState( new osg::State );
|
||||||
getState()->setGraphicsContext(this);
|
getState()->setGraphicsContext(this);
|
||||||
|
|
||||||
if (_traits.valid() && _traits->sharedContext)
|
if (_traits.valid() && _traits->sharedContext.valid())
|
||||||
{
|
{
|
||||||
getState()->setContextID( _traits->sharedContext->getState()->getContextID() );
|
getState()->setContextID( _traits->sharedContext->getState()->getContextID() );
|
||||||
incrementContextIDUsageCount( getState()->getContextID() );
|
incrementContextIDUsageCount( getState()->getContextID() );
|
||||||
|
@ -299,7 +299,7 @@ void GraphicsWindowWX::init()
|
|||||||
setState( new osg::State );
|
setState( new osg::State );
|
||||||
getState()->setGraphicsContext(this);
|
getState()->setGraphicsContext(this);
|
||||||
|
|
||||||
if (_traits.valid() && _traits->sharedContext)
|
if (_traits.valid() && _traits->sharedContext.valid())
|
||||||
{
|
{
|
||||||
getState()->setContextID( _traits->sharedContext->getState()->getContextID() );
|
getState()->setContextID( _traits->sharedContext->getState()->getContextID() );
|
||||||
incrementContextIDUsageCount( getState()->getContextID() );
|
incrementContextIDUsageCount( getState()->getContextID() );
|
||||||
|
@ -128,7 +128,7 @@ class OSG_EXPORT GraphicsContext : public Object
|
|||||||
bool getContextVersion(unsigned int& major, unsigned int& minor) const;
|
bool getContextVersion(unsigned int& major, unsigned int& minor) const;
|
||||||
|
|
||||||
// shared context
|
// shared context
|
||||||
GraphicsContext* sharedContext;
|
osg::observer_ptr<GraphicsContext> sharedContext;
|
||||||
|
|
||||||
osg::ref_ptr<osg::Referenced> inheritedWindowData;
|
osg::ref_ptr<osg::Referenced> inheritedWindowData;
|
||||||
|
|
||||||
|
@ -247,7 +247,7 @@ class GraphicsWindowEmbedded : public GraphicsWindow
|
|||||||
setState( new osg::State );
|
setState( new osg::State );
|
||||||
getState()->setGraphicsContext(this);
|
getState()->setGraphicsContext(this);
|
||||||
|
|
||||||
if (_traits.valid() && _traits->sharedContext)
|
if (_traits.valid() && _traits->sharedContext.valid())
|
||||||
{
|
{
|
||||||
getState()->setContextID( _traits->sharedContext->getState()->getContextID() );
|
getState()->setContextID( _traits->sharedContext->getState()->getContextID() );
|
||||||
incrementContextIDUsageCount( getState()->getContextID() );
|
incrementContextIDUsageCount( getState()->getContextID() );
|
||||||
|
@ -48,7 +48,7 @@ class GraphicsWindowCarbon : public osgViewer::GraphicsWindow, public osgViewer:
|
|||||||
setState( new osg::State );
|
setState( new osg::State );
|
||||||
getState()->setGraphicsContext(this);
|
getState()->setGraphicsContext(this);
|
||||||
|
|
||||||
if (_traits.valid() && _traits->sharedContext)
|
if (_traits.valid() && _traits->sharedContext.valid())
|
||||||
{
|
{
|
||||||
getState()->setContextID( _traits->sharedContext->getState()->getContextID() );
|
getState()->setContextID( _traits->sharedContext->getState()->getContextID() );
|
||||||
incrementContextIDUsageCount( getState()->getContextID() );
|
incrementContextIDUsageCount( getState()->getContextID() );
|
||||||
|
@ -45,7 +45,7 @@ class OSGVIEWER_EXPORT PixelBufferCarbon : public osg::GraphicsContext, public o
|
|||||||
setState( new osg::State );
|
setState( new osg::State );
|
||||||
getState()->setGraphicsContext(this);
|
getState()->setGraphicsContext(this);
|
||||||
|
|
||||||
if (_traits.valid() && _traits->sharedContext)
|
if (_traits.valid() && _traits->sharedContext.valid())
|
||||||
{
|
{
|
||||||
getState()->setContextID( _traits->sharedContext->getState()->getContextID() );
|
getState()->setContextID( _traits->sharedContext->getState()->getContextID() );
|
||||||
incrementContextIDUsageCount( getState()->getContextID() );
|
incrementContextIDUsageCount( getState()->getContextID() );
|
||||||
|
@ -76,7 +76,7 @@ class GraphicsWindowCocoa : public osgViewer::GraphicsWindow, public osgViewer::
|
|||||||
setState( new osg::State );
|
setState( new osg::State );
|
||||||
getState()->setGraphicsContext(this);
|
getState()->setGraphicsContext(this);
|
||||||
|
|
||||||
if (_traits.valid() && _traits->sharedContext)
|
if (_traits.valid() && _traits->sharedContext.valid())
|
||||||
{
|
{
|
||||||
getState()->setContextID( _traits->sharedContext->getState()->getContextID() );
|
getState()->setContextID( _traits->sharedContext->getState()->getContextID() );
|
||||||
incrementContextIDUsageCount( getState()->getContextID() );
|
incrementContextIDUsageCount( getState()->getContextID() );
|
||||||
|
@ -47,7 +47,7 @@ class OSGVIEWER_EXPORT PixelBufferCocoa : public osg::GraphicsContext, public os
|
|||||||
setState( new osg::State );
|
setState( new osg::State );
|
||||||
getState()->setGraphicsContext(this);
|
getState()->setGraphicsContext(this);
|
||||||
|
|
||||||
if (_traits.valid() && _traits->sharedContext)
|
if (_traits.valid() && _traits->sharedContext.valid())
|
||||||
{
|
{
|
||||||
getState()->setContextID( _traits->sharedContext->getState()->getContextID() );
|
getState()->setContextID( _traits->sharedContext->getState()->getContextID() );
|
||||||
incrementContextIDUsageCount( getState()->getContextID() );
|
incrementContextIDUsageCount( getState()->getContextID() );
|
||||||
|
@ -72,7 +72,7 @@ class GraphicsWindowIOS : public osgViewer::GraphicsWindow
|
|||||||
setState( new osg::State );
|
setState( new osg::State );
|
||||||
getState()->setGraphicsContext(this);
|
getState()->setGraphicsContext(this);
|
||||||
|
|
||||||
if (_traits.valid() && _traits->sharedContext)
|
if (_traits.valid() && _traits->sharedContext.valid())
|
||||||
{
|
{
|
||||||
getState()->setContextID( _traits->sharedContext->getState()->getContextID() );
|
getState()->setContextID( _traits->sharedContext->getState()->getContextID() );
|
||||||
incrementContextIDUsageCount( getState()->getContextID() );
|
incrementContextIDUsageCount( getState()->getContextID() );
|
||||||
|
@ -59,7 +59,7 @@ class OSGVIEWER_EXPORT GraphicsWindowX11 : public osgViewer::GraphicsWindow, pub
|
|||||||
setState( new osg::State );
|
setState( new osg::State );
|
||||||
getState()->setGraphicsContext(this);
|
getState()->setGraphicsContext(this);
|
||||||
|
|
||||||
if (_traits.valid() && _traits->sharedContext)
|
if (_traits.valid() && _traits->sharedContext.valid())
|
||||||
{
|
{
|
||||||
getState()->setContextID( _traits->sharedContext->getState()->getContextID() );
|
getState()->setContextID( _traits->sharedContext->getState()->getContextID() );
|
||||||
incrementContextIDUsageCount( getState()->getContextID() );
|
incrementContextIDUsageCount( getState()->getContextID() );
|
||||||
|
@ -382,7 +382,7 @@ bool GraphicsWindowQt::init( QWidget* parent, const QGLWidget* shareWidget, Qt::
|
|||||||
{
|
{
|
||||||
// shareWidget
|
// shareWidget
|
||||||
if ( !shareWidget ) {
|
if ( !shareWidget ) {
|
||||||
GraphicsWindowQt* sharedContextQt = dynamic_cast<GraphicsWindowQt*>(_traits->sharedContext);
|
GraphicsWindowQt* sharedContextQt = dynamic_cast<GraphicsWindowQt*>(_traits->sharedContext.get());
|
||||||
if ( sharedContextQt )
|
if ( sharedContextQt )
|
||||||
shareWidget = sharedContextQt->getGLWidget();
|
shareWidget = sharedContextQt->getGLWidget();
|
||||||
}
|
}
|
||||||
@ -422,7 +422,7 @@ bool GraphicsWindowQt::init( QWidget* parent, const QGLWidget* shareWidget, Qt::
|
|||||||
getState()->setGraphicsContext(this);
|
getState()->setGraphicsContext(this);
|
||||||
|
|
||||||
// initialize contextID
|
// initialize contextID
|
||||||
if ( _traits.valid() && _traits->sharedContext )
|
if ( _traits.valid() && _traits->sharedContext.valid() )
|
||||||
{
|
{
|
||||||
getState()->setContextID( _traits->sharedContext->getState()->getContextID() );
|
getState()->setContextID( _traits->sharedContext->getState()->getContextID() );
|
||||||
incrementContextIDUsageCount( getState()->getContextID() );
|
incrementContextIDUsageCount( getState()->getContextID() );
|
||||||
|
@ -399,7 +399,7 @@ bool GraphicsWindowCarbon::realizeImplementation()
|
|||||||
// create the context
|
// create the context
|
||||||
AGLContext sharedContextCarbon = NULL;
|
AGLContext sharedContextCarbon = NULL;
|
||||||
|
|
||||||
GraphicsHandleCarbon* graphicsHandleCarbon = dynamic_cast<GraphicsHandleCarbon*>(_traits->sharedContext);
|
GraphicsHandleCarbon* graphicsHandleCarbon = dynamic_cast<GraphicsHandleCarbon*>(_traits->sharedContext.get());
|
||||||
if (graphicsHandleCarbon)
|
if (graphicsHandleCarbon)
|
||||||
{
|
{
|
||||||
sharedContextCarbon = graphicsHandleCarbon->getAGLContext();
|
sharedContextCarbon = graphicsHandleCarbon->getAGLContext();
|
||||||
|
@ -1186,7 +1186,7 @@ bool GraphicsWindowCocoa::realizeImplementation()
|
|||||||
// create the context
|
// create the context
|
||||||
NSOpenGLContext* sharedContext = NULL;
|
NSOpenGLContext* sharedContext = NULL;
|
||||||
|
|
||||||
GraphicsHandleCocoa* graphicsHandleCocoa = dynamic_cast<GraphicsHandleCocoa*>(_traits->sharedContext);
|
GraphicsHandleCocoa* graphicsHandleCocoa = dynamic_cast<GraphicsHandleCocoa*>(_traits->sharedContext.get());
|
||||||
if (graphicsHandleCocoa)
|
if (graphicsHandleCocoa)
|
||||||
{
|
{
|
||||||
sharedContext = graphicsHandleCocoa->getNSOpenGLContext();
|
sharedContext = graphicsHandleCocoa->getNSOpenGLContext();
|
||||||
|
@ -1150,7 +1150,7 @@ GraphicsWindowWin32::GraphicsWindowWin32( osg::GraphicsContext::Traits* traits )
|
|||||||
setState( new osg::State );
|
setState( new osg::State );
|
||||||
getState()->setGraphicsContext(this);
|
getState()->setGraphicsContext(this);
|
||||||
|
|
||||||
if (_traits.valid() && _traits->sharedContext)
|
if (_traits.valid() && _traits->sharedContext.valid())
|
||||||
{
|
{
|
||||||
getState()->setContextID( _traits->sharedContext->getState()->getContextID() );
|
getState()->setContextID( _traits->sharedContext->getState()->getContextID() );
|
||||||
incrementContextIDUsageCount( getState()->getContextID() );
|
incrementContextIDUsageCount( getState()->getContextID() );
|
||||||
@ -1903,7 +1903,7 @@ bool GraphicsWindowWin32::realizeImplementation()
|
|||||||
if (!_initialized) return false;
|
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
|
// make context current so we can test capabilities and set up context sharing
|
||||||
struct RestoreContext
|
struct RestoreContext
|
||||||
@ -1932,7 +1932,7 @@ bool GraphicsWindowWin32::realizeImplementation()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// set up sharing of contexts if required
|
// 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 (graphicsHandleWin32)
|
||||||
{
|
{
|
||||||
if (!wglShareLists(graphicsHandleWin32->getWGLContext(), getWGLContext()))
|
if (!wglShareLists(graphicsHandleWin32->getWGLContext(), getWGLContext()))
|
||||||
|
@ -717,7 +717,7 @@ void GraphicsWindowX11::init()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// get any shared GLX contexts
|
// 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 sharedContext = graphicsHandleX11 ? graphicsHandleX11->getContext() : 0;
|
||||||
|
|
||||||
#ifdef OSG_USE_EGL
|
#ifdef OSG_USE_EGL
|
||||||
|
@ -81,7 +81,7 @@ bool PixelBufferCarbon::realizeImplementation()
|
|||||||
AGLContext sharedContext = NULL;
|
AGLContext sharedContext = NULL;
|
||||||
|
|
||||||
// get any shared AGL contexts
|
// get any shared AGL contexts
|
||||||
GraphicsHandleCarbon* graphicsHandleCarbon = dynamic_cast<GraphicsHandleCarbon*>(_traits->sharedContext);
|
GraphicsHandleCarbon* graphicsHandleCarbon = dynamic_cast<GraphicsHandleCarbon*>(_traits->sharedContext.get());
|
||||||
if (graphicsHandleCarbon)
|
if (graphicsHandleCarbon)
|
||||||
{
|
{
|
||||||
sharedContext = graphicsHandleCarbon->getAGLContext();
|
sharedContext = graphicsHandleCarbon->getAGLContext();
|
||||||
|
@ -63,7 +63,7 @@ bool PixelBufferCocoa::realizeImplementation()
|
|||||||
// create the context
|
// create the context
|
||||||
NSOpenGLContext* sharedContext = NULL;
|
NSOpenGLContext* sharedContext = NULL;
|
||||||
|
|
||||||
GraphicsHandleCocoa* graphicsHandleCocoa = dynamic_cast<GraphicsHandleCocoa*>(_traits->sharedContext);
|
GraphicsHandleCocoa* graphicsHandleCocoa = dynamic_cast<GraphicsHandleCocoa*>(_traits->sharedContext.get());
|
||||||
if (graphicsHandleCocoa)
|
if (graphicsHandleCocoa)
|
||||||
{
|
{
|
||||||
sharedContext = graphicsHandleCocoa->getNSOpenGLContext();
|
sharedContext = graphicsHandleCocoa->getNSOpenGLContext();
|
||||||
|
@ -463,7 +463,7 @@ PixelBufferWin32::PixelBufferWin32( osg::GraphicsContext::Traits* traits ):
|
|||||||
setState( new osg::State );
|
setState( new osg::State );
|
||||||
getState()->setGraphicsContext( this );
|
getState()->setGraphicsContext( this );
|
||||||
|
|
||||||
if (_traits.valid() && _traits->sharedContext )
|
if (_traits.valid() && _traits->sharedContext.valid() )
|
||||||
{
|
{
|
||||||
getState()->setContextID( _traits->sharedContext->getState()->getContextID() );
|
getState()->setContextID( _traits->sharedContext->getState()->getContextID() );
|
||||||
incrementContextIDUsageCount( getState()->getContextID() );
|
incrementContextIDUsageCount( getState()->getContextID() );
|
||||||
@ -658,9 +658,9 @@ bool PixelBufferWin32::realizeImplementation()
|
|||||||
|
|
||||||
if (!_initialized) return false;
|
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 (graphicsHandleWin32)
|
||||||
{
|
{
|
||||||
if ( !wglShareLists(graphicsHandleWin32->getWGLContext(), _hglrc) )
|
if ( !wglShareLists(graphicsHandleWin32->getWGLContext(), _hglrc) )
|
||||||
|
@ -43,7 +43,7 @@ PixelBufferX11::PixelBufferX11(osg::GraphicsContext::Traits* traits)
|
|||||||
setState( new osg::State );
|
setState( new osg::State );
|
||||||
getState()->setGraphicsContext(this);
|
getState()->setGraphicsContext(this);
|
||||||
|
|
||||||
if (_traits.valid() && _traits->sharedContext)
|
if (_traits.valid() && _traits->sharedContext.valid())
|
||||||
{
|
{
|
||||||
getState()->setContextID( _traits->sharedContext->getState()->getContextID() );
|
getState()->setContextID( _traits->sharedContext->getState()->getContextID() );
|
||||||
incrementContextIDUsageCount( getState()->getContextID() );
|
incrementContextIDUsageCount( getState()->getContextID() );
|
||||||
@ -216,7 +216,7 @@ void PixelBufferX11::init()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// get any shared GLX contexts
|
// 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 sharedContext = graphicsHandleX11 ? graphicsHandleX11->getContext() : 0;
|
||||||
|
|
||||||
_context = glXCreateContext( _display, _visualInfo, sharedContext, True );
|
_context = glXCreateContext( _display, _visualInfo, sharedContext, True );
|
||||||
|
Loading…
Reference in New Issue
Block a user