diff --git a/include/osgViewer/GraphicsWindowWin32 b/include/osgViewer/GraphicsWindowWin32 index 6688256b3..24da74e52 100644 --- a/include/osgViewer/GraphicsWindowWin32 +++ b/include/osgViewer/GraphicsWindowWin32 @@ -98,7 +98,7 @@ class GraphicsWindowWin32 : public osgViewer::GraphicsWindow int getScreenNumberContainingWindow( int& _screenOriginX, int& _screenOriginY ); - HGLRC& getWGLContext() { return _hglrc; } + HGLRC getWGLContext() { return _hglrc; } HWND _hwnd; HDC _hdc; diff --git a/src/osgViewer/GraphicsWindowWin32.cpp b/src/osgViewer/GraphicsWindowWin32.cpp index 4a60558ed..00dca8427 100644 --- a/src/osgViewer/GraphicsWindowWin32.cpp +++ b/src/osgViewer/GraphicsWindowWin32.cpp @@ -1411,13 +1411,17 @@ bool GraphicsWindowWin32::realizeImplementation() init(); if (!_initialized) return false; - if (_traits.valid && _traits->sharedContext) + if (_traits.valid() && _traits->sharedContext) { GraphicsWindowWin32* sharedContextWin32 = dynamic_cast(_traits->sharedContext); if (sharedContextWin32) { - makeCurrent(); - wglShareLists( sharedContextWin32->getWGLContext(), getWGLContext() ); + if (!makeCurrent()) return false; + if (!wglShareLists(sharedContextWin32->getWGLContext(), getWGLContext())) + { + reportErrorForScreen("GraphicsWindowWin32::realizeImplementation() - Unable to share OpenGL context", _traits->screenNum, ::GetLastError()); + return false; + } } } }