Index: /OpenSceneGraph/trunk/include/osg/GraphicsContext
===================================================================
--- /OpenSceneGraph/trunk/include/osg/GraphicsContext (revision 13041)
+++ /OpenSceneGraph/trunk/include/osg/GraphicsContext (revision 13130)
@@ -129,5 +129,5 @@
 
             // shared context
-            GraphicsContext* sharedContext;
+            osg::observer_ptr<GraphicsContext> sharedContext;
 
             osg::ref_ptr<osg::Referenced> inheritedWindowData;
Index: /OpenSceneGraph/trunk/include/osgViewer/GraphicsWindow
===================================================================
--- /OpenSceneGraph/trunk/include/osgViewer/GraphicsWindow (revision 12305)
+++ /OpenSceneGraph/trunk/include/osgViewer/GraphicsWindow (revision 13130)
@@ -248,5 +248,5 @@
                 getState()->setGraphicsContext(this);
 
-                if (_traits.valid() && _traits->sharedContext)
+                if (_traits.valid() && _traits->sharedContext.valid())
                 {
                     getState()->setContextID( _traits->sharedContext->getState()->getContextID() );
Index: /OpenSceneGraph/trunk/include/osgViewer/api/Carbon/PixelBufferCarbon
===================================================================
--- /OpenSceneGraph/trunk/include/osgViewer/api/Carbon/PixelBufferCarbon (revision 12292)
+++ /OpenSceneGraph/trunk/include/osgViewer/api/Carbon/PixelBufferCarbon (revision 13130)
@@ -46,5 +46,5 @@
                 getState()->setGraphicsContext(this);
 
-                if (_traits.valid() && _traits->sharedContext)
+                if (_traits.valid() && _traits->sharedContext.valid())
                 {
                     getState()->setContextID( _traits->sharedContext->getState()->getContextID() );
Index: /OpenSceneGraph/trunk/include/osgViewer/api/Carbon/GraphicsWindowCarbon
===================================================================
--- /OpenSceneGraph/trunk/include/osgViewer/api/Carbon/GraphicsWindowCarbon (revision 11357)
+++ /OpenSceneGraph/trunk/include/osgViewer/api/Carbon/GraphicsWindowCarbon (revision 13130)
@@ -49,5 +49,5 @@
                 getState()->setGraphicsContext(this);
 
-                if (_traits.valid() && _traits->sharedContext)
+                if (_traits.valid() && _traits->sharedContext.valid())
                 {
                     getState()->setContextID( _traits->sharedContext->getState()->getContextID() );
Index: /OpenSceneGraph/trunk/include/osgViewer/api/Cocoa/PixelBufferCocoa
===================================================================
--- /OpenSceneGraph/trunk/include/osgViewer/api/Cocoa/PixelBufferCocoa (revision 12292)
+++ /OpenSceneGraph/trunk/include/osgViewer/api/Cocoa/PixelBufferCocoa (revision 13130)
@@ -48,5 +48,5 @@
                 getState()->setGraphicsContext(this);
 
-                if (_traits.valid() && _traits->sharedContext)
+                if (_traits.valid() && _traits->sharedContext.valid())
                 {
                     getState()->setContextID( _traits->sharedContext->getState()->getContextID() );
Index: /OpenSceneGraph/trunk/include/osgViewer/api/Cocoa/GraphicsWindowCocoa
===================================================================
--- /OpenSceneGraph/trunk/include/osgViewer/api/Cocoa/GraphicsWindowCocoa (revision 12938)
+++ /OpenSceneGraph/trunk/include/osgViewer/api/Cocoa/GraphicsWindowCocoa (revision 13130)
@@ -77,5 +77,5 @@
                 getState()->setGraphicsContext(this);
 
-                if (_traits.valid() && _traits->sharedContext)
+                if (_traits.valid() && _traits->sharedContext.valid())
                 {
                     getState()->setContextID( _traits->sharedContext->getState()->getContextID() );
Index: /OpenSceneGraph/trunk/include/osgViewer/api/X11/GraphicsWindowX11
===================================================================
--- /OpenSceneGraph/trunk/include/osgViewer/api/X11/GraphicsWindowX11 (revision 12125)
+++ /OpenSceneGraph/trunk/include/osgViewer/api/X11/GraphicsWindowX11 (revision 13130)
@@ -60,5 +60,5 @@
                 getState()->setGraphicsContext(this);
 
-                if (_traits.valid() && _traits->sharedContext)
+                if (_traits.valid() && _traits->sharedContext.valid())
                 {
                     getState()->setContextID( _traits->sharedContext->getState()->getContextID() );
Index: /OpenSceneGraph/trunk/include/osgViewer/api/IOS/GraphicsWindowIOS
===================================================================
--- /OpenSceneGraph/trunk/include/osgViewer/api/IOS/GraphicsWindowIOS (revision 12520)
+++ /OpenSceneGraph/trunk/include/osgViewer/api/IOS/GraphicsWindowIOS (revision 13130)
@@ -73,5 +73,5 @@
                 getState()->setGraphicsContext(this);
 
-                if (_traits.valid() && _traits->sharedContext)
+                if (_traits.valid() && _traits->sharedContext.valid())
                 {
                     getState()->setContextID( _traits->sharedContext->getState()->getContextID() );
Index: /OpenSceneGraph/trunk/src/osgQt/GraphicsWindowQt.cpp
===================================================================
--- /OpenSceneGraph/trunk/src/osgQt/GraphicsWindowQt.cpp (revision 13041)
+++ /OpenSceneGraph/trunk/src/osgQt/GraphicsWindowQt.cpp (revision 13130)
@@ -383,5 +383,5 @@
         // shareWidget
         if ( !shareWidget ) {
-            GraphicsWindowQt* sharedContextQt = dynamic_cast<GraphicsWindowQt*>(_traits->sharedContext);
+            GraphicsWindowQt* sharedContextQt = dynamic_cast<GraphicsWindowQt*>(_traits->sharedContext.get());
             if ( sharedContextQt )
                 shareWidget = sharedContextQt->getGLWidget();
@@ -423,5 +423,5 @@
 
     // initialize contextID
-    if ( _traits.valid() && _traits->sharedContext )
+    if ( _traits.valid() && _traits->sharedContext.valid() )
     {
         getState()->setContextID( _traits->sharedContext->getState()->getContextID() );
Index: /OpenSceneGraph/trunk/src/osgViewer/PixelBufferWin32.cpp
===================================================================
--- /OpenSceneGraph/trunk/src/osgViewer/PixelBufferWin32.cpp (revision 13041)
+++ /OpenSceneGraph/trunk/src/osgViewer/PixelBufferWin32.cpp (revision 13130)
@@ -464,5 +464,5 @@
         getState()->setGraphicsContext( this );
 
-        if (_traits.valid() && _traits->sharedContext )
+        if (_traits.valid() && _traits->sharedContext.valid() )
         {
             getState()->setContextID( _traits->sharedContext->getState()->getContextID() );
@@ -659,7 +659,7 @@
     if (!_initialized) return false;
 
-    if ( _traits->sharedContext )
-    {
-        GraphicsHandleWin32* graphicsHandleWin32 = dynamic_cast<GraphicsHandleWin32*>(_traits->sharedContext);
+    if ( _traits->sharedContext.valid() )
+    {
+        GraphicsHandleWin32* graphicsHandleWin32 = dynamic_cast<GraphicsHandleWin32*>(_traits->sharedContext.get());
         if (graphicsHandleWin32)
         {
Index: /OpenSceneGraph/trunk/src/osgViewer/PixelBufferCarbon.cpp
===================================================================
--- /OpenSceneGraph/trunk/src/osgViewer/PixelBufferCarbon.cpp (revision 13041)
+++ /OpenSceneGraph/trunk/src/osgViewer/PixelBufferCarbon.cpp (revision 13130)
@@ -82,5 +82,5 @@
 
     // get any shared AGL contexts
-    GraphicsHandleCarbon* graphicsHandleCarbon = dynamic_cast<GraphicsHandleCarbon*>(_traits->sharedContext);
+    GraphicsHandleCarbon* graphicsHandleCarbon = dynamic_cast<GraphicsHandleCarbon*>(_traits->sharedContext.get());
     if (graphicsHandleCarbon)
     {
Index: /OpenSceneGraph/trunk/src/osgViewer/PixelBufferX11.cpp
===================================================================
--- /OpenSceneGraph/trunk/src/osgViewer/PixelBufferX11.cpp (revision 13041)
+++ /OpenSceneGraph/trunk/src/osgViewer/PixelBufferX11.cpp (revision 13130)
@@ -44,5 +44,5 @@
         getState()->setGraphicsContext(this);
 
-        if (_traits.valid() && _traits->sharedContext)
+        if (_traits.valid() && _traits->sharedContext.valid())
         {
             getState()->setContextID( _traits->sharedContext->getState()->getContextID() );
@@ -217,5 +217,5 @@
 
     // 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;
 
Index: /OpenSceneGraph/trunk/src/osgViewer/PixelBufferCocoa.mm
===================================================================
--- /OpenSceneGraph/trunk/src/osgViewer/PixelBufferCocoa.mm (revision 13036)
+++ /OpenSceneGraph/trunk/src/osgViewer/PixelBufferCocoa.mm (revision 13130)
@@ -64,5 +64,5 @@
     NSOpenGLContext* sharedContext = NULL;
     
-    GraphicsHandleCocoa* graphicsHandleCocoa = dynamic_cast<GraphicsHandleCocoa*>(_traits->sharedContext);
+    GraphicsHandleCocoa* graphicsHandleCocoa = dynamic_cast<GraphicsHandleCocoa*>(_traits->sharedContext.get());
     if (graphicsHandleCocoa) 
     {
Index: /OpenSceneGraph/trunk/src/osgViewer/GraphicsWindowWin32.cpp
===================================================================
--- /OpenSceneGraph/trunk/src/osgViewer/GraphicsWindowWin32.cpp (revision 13041)
+++ /OpenSceneGraph/trunk/src/osgViewer/GraphicsWindowWin32.cpp (revision 13130)
@@ -1151,5 +1151,5 @@
         getState()->setGraphicsContext(this);
 
-        if (_traits.valid() && _traits->sharedContext)
+        if (_traits.valid() && _traits->sharedContext.valid())
         {
             getState()->setContextID( _traits->sharedContext->getState()->getContextID() );
@@ -1904,5 +1904,5 @@
     }
 
-    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
@@ -1933,5 +1933,5 @@
 
         // set up sharing of contexts if required
-        GraphicsHandleWin32* graphicsHandleWin32 = dynamic_cast<GraphicsHandleWin32*>(_traits->sharedContext);
+        GraphicsHandleWin32* graphicsHandleWin32 = dynamic_cast<GraphicsHandleWin32*>(_traits->sharedContext.get());
         if (graphicsHandleWin32)
         {
Index: /OpenSceneGraph/trunk/src/osgViewer/GraphicsWindowCarbon.cpp
===================================================================
--- /OpenSceneGraph/trunk/src/osgViewer/GraphicsWindowCarbon.cpp (revision 13041)
+++ /OpenSceneGraph/trunk/src/osgViewer/GraphicsWindowCarbon.cpp (revision 13130)
@@ -400,5 +400,5 @@
     AGLContext sharedContextCarbon = NULL;
 
-    GraphicsHandleCarbon* graphicsHandleCarbon = dynamic_cast<GraphicsHandleCarbon*>(_traits->sharedContext);
+    GraphicsHandleCarbon* graphicsHandleCarbon = dynamic_cast<GraphicsHandleCarbon*>(_traits->sharedContext.get());
     if (graphicsHandleCarbon)
     {
Index: /OpenSceneGraph/trunk/src/osgViewer/GraphicsWindowX11.cpp
===================================================================
--- /OpenSceneGraph/trunk/src/osgViewer/GraphicsWindowX11.cpp (revision 13041)
+++ /OpenSceneGraph/trunk/src/osgViewer/GraphicsWindowX11.cpp (revision 13130)
@@ -718,5 +718,5 @@
 
     // 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;
 
Index: /OpenSceneGraph/trunk/src/osgViewer/GraphicsWindowCocoa.mm
===================================================================
--- /OpenSceneGraph/trunk/src/osgViewer/GraphicsWindowCocoa.mm (revision 12939)
+++ /OpenSceneGraph/trunk/src/osgViewer/GraphicsWindowCocoa.mm (revision 13130)
@@ -1187,5 +1187,5 @@
     NSOpenGLContext* sharedContext = NULL;
 
-    GraphicsHandleCocoa* graphicsHandleCocoa = dynamic_cast<GraphicsHandleCocoa*>(_traits->sharedContext);
+    GraphicsHandleCocoa* graphicsHandleCocoa = dynamic_cast<GraphicsHandleCocoa*>(_traits->sharedContext.get());
     if (graphicsHandleCocoa)
     {
Index: /OpenSceneGraph/trunk/examples/osgviewerWX/osgviewerWX.cpp
===================================================================
--- /OpenSceneGraph/trunk/examples/osgviewerWX/osgviewerWX.cpp (revision 12814)
+++ /OpenSceneGraph/trunk/examples/osgviewerWX/osgviewerWX.cpp (revision 13130)
@@ -300,5 +300,5 @@
         getState()->setGraphicsContext(this);
 
-        if (_traits.valid() && _traits->sharedContext)
+        if (_traits.valid() && _traits->sharedContext.valid())
         {
             getState()->setContextID( _traits->sharedContext->getState()->getContextID() );
Index: /OpenSceneGraph/trunk/examples/osgviewerFOX/FOX_OSG.cpp
===================================================================
--- /OpenSceneGraph/trunk/examples/osgviewerFOX/FOX_OSG.cpp (revision 12292)
+++ /OpenSceneGraph/trunk/examples/osgviewerFOX/FOX_OSG.cpp (revision 13130)
@@ -49,5 +49,5 @@
 		getState()->setGraphicsContext(this);
 
-		if (_traits.valid() && _traits->sharedContext)
+		if (_traits.valid() && _traits->sharedContext.valid())
 		{
 			getState()->setContextID( _traits->sharedContext->getState()->getContextID() );
