Kaydet (Commit) a00df90e authored tarafından Miklos Vajna's avatar Miklos Vajna

vcl opengl: fix setting up debug context on Windows

At least with my AMD card, in case of SAL_FORCEGL=1 the startup crashes
quite early. DrMemory says:

~~Dr.M~~ Error #1: UNADDRESSABLE ACCESS: writing 0x00001414-0x00001415 1 byte(s)
~~Dr.M~~ # 0 atioglxx.dll!DrvPresentBuffers                          +0xd6ea6  (0x09a248f6 <atioglxx.dll+0x1248f6>)
~~Dr.M~~ # 1 atioglxx.dll!DrvPresentBuffers                          +0x3c069c (0x09d0e0ed <atioglxx.dll+0x40e0ed>)
~~Dr.M~~ # 2 vcllo.dll!OpenGLContext::InitGLEW                        [c:\lo\master\vcl\source\opengl\openglcontext.cxx:949]
~~Dr.M~~ # 3 vcllo.dll!OpenGLContext::ImplInit                        [c:\lo\master\vcl\source\opengl\openglcontext.cxx:866]
~~Dr.M~~ # 4 vcllo.dll!OpenGLContext::init                            [c:\lo\master\vcl\source\opengl\openglcontext.cxx:786]
~~Dr.M~~ # 5 vcllo.dll!WinOpenGLSalGraphicsImpl::CreateWinContext     [c:\lo\master\vcl\opengl\win\gdiimpl.cxx:36]

Turns out that in order to enable the GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB
extension, the GL context must be created with WGL_CONTEXT_DEBUG_BIT_ARB
set. It seems that other drivers did not enforce this so far, but in
this case the driver just crashes without this.

Fix the problem by splitting out the debug setup part of InitGLEW() into
a new InitGLEWDebugging(), and at least on Windows call it only after
wglCreateContextAttribsARB() and wglMakeCurrent(). Additionally make
sure that in the debug case the necessary flag is passed to
wglCreateContextAttribsARB().

Change-Id: I6b77e0c06fd85fdae0386a0801f1de1838524586
Reviewed-on: https://gerrit.libreoffice.org/17750Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
Tested-by: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
üst fcd4c6da
...@@ -234,6 +234,7 @@ public: ...@@ -234,6 +234,7 @@ public:
private: private:
SAL_DLLPRIVATE bool InitGLEW(); SAL_DLLPRIVATE bool InitGLEW();
SAL_DLLPRIVATE void InitGLEWDebugging();
SAL_DLLPRIVATE bool initWindow(); SAL_DLLPRIVATE bool initWindow();
SAL_DLLPRIVATE bool ImplInit(); SAL_DLLPRIVATE bool ImplInit();
#if defined( UNX ) && !defined MACOSX && !defined IOS && !defined ANDROID && !defined(LIBO_HEADLESS) #if defined( UNX ) && !defined MACOSX && !defined IOS && !defined ANDROID && !defined(LIBO_HEADLESS)
......
...@@ -771,7 +771,9 @@ bool OpenGLContext::ImplInit() ...@@ -771,7 +771,9 @@ bool OpenGLContext::ImplInit()
} }
} }
return InitGLEW(); bool bRet = InitGLEW();
InitGLEWDebugging();
return bRet;
} }
#elif defined( _WIN32 ) #elif defined( _WIN32 )
...@@ -875,7 +877,14 @@ bool OpenGLContext::ImplInit() ...@@ -875,7 +877,14 @@ bool OpenGLContext::ImplInit()
// now setup the shared context; this needs a temporary context already // now setup the shared context; this needs a temporary context already
// set up in order to work // set up in order to work
m_aGLWin.hRC = wglCreateContextAttribsARB(m_aGLWin.hDC, hSharedCtx, NULL); int attribs [] =
{
#ifdef DBG_UTIL
WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_DEBUG_BIT_ARB,
#endif
0
};
m_aGLWin.hRC = wglCreateContextAttribsARB(m_aGLWin.hDC, hSharedCtx, attribs);
if (m_aGLWin.hRC == 0) if (m_aGLWin.hRC == 0)
{ {
ImplWriteLastError(GetLastError(), "wglCreateContextAttribsARB in OpenGLContext::ImplInit"); ImplWriteLastError(GetLastError(), "wglCreateContextAttribsARB in OpenGLContext::ImplInit");
...@@ -884,6 +893,7 @@ bool OpenGLContext::ImplInit() ...@@ -884,6 +893,7 @@ bool OpenGLContext::ImplInit()
} }
wglMakeCurrent(NULL, NULL); wglMakeCurrent(NULL, NULL);
InitGLEWDebugging();
wglDeleteContext(hTempRC); wglDeleteContext(hTempRC);
if (!wglMakeCurrent(m_aGLWin.hDC, m_aGLWin.hRC)) if (!wglMakeCurrent(m_aGLWin.hDC, m_aGLWin.hRC))
...@@ -911,7 +921,9 @@ bool OpenGLContext::ImplInit() ...@@ -911,7 +921,9 @@ bool OpenGLContext::ImplInit()
NSOpenGLView* pView = getOpenGLView(); NSOpenGLView* pView = getOpenGLView();
OpenGLWrapper::makeCurrent(pView); OpenGLWrapper::makeCurrent(pView);
return InitGLEW(); bool bRet = InitGLEW();
InitGLEWDebugging();
return bRet;
} }
#else #else
...@@ -940,6 +952,13 @@ bool OpenGLContext::InitGLEW() ...@@ -940,6 +952,13 @@ bool OpenGLContext::InitGLEW()
bGlewInit = true; bGlewInit = true;
} }
SAL_INFO("vcl.opengl", "OpenGLContext::ImplInit----end");
mbInitialized = true;
return true;
}
void OpenGLContext::InitGLEWDebugging()
{
#ifdef DBG_UTIL #ifdef DBG_UTIL
// only enable debug output in dbgutil build // only enable debug output in dbgutil build
if( GLEW_ARB_debug_output) if( GLEW_ARB_debug_output)
...@@ -957,10 +976,6 @@ bool OpenGLContext::InitGLEW() ...@@ -957,10 +976,6 @@ bool OpenGLContext::InitGLEW()
} }
#endif #endif
SAL_INFO("vcl.opengl", "OpenGLContext::ImplInit----end");
mbInitialized = true;
return true;
} }
void OpenGLContext::setWinPosAndSize(const Point &rPos, const Size& rSize) void OpenGLContext::setWinPosAndSize(const Point &rPos, const Size& rSize)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment