diff --git a/plugins/GSdx/GSWnd.cpp b/plugins/GSdx/GSWnd.cpp index 88150e7c61..97ac519ae1 100644 --- a/plugins/GSdx/GSWnd.cpp +++ b/plugins/GSdx/GSWnd.cpp @@ -225,6 +225,13 @@ GSWnd::~GSWnd() } } +static bool ctxError = false; +static int ctxErrorHandler(Display *dpy, XErrorEvent *ev) +{ + ctxError = true; + return 0; +} + bool GSWnd::CreateContext(int major, int minor) { if ( !m_XDisplay || !m_Xwindow ) @@ -255,6 +262,11 @@ bool GSWnd::CreateContext(int major, int minor) PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribsARB = (PFNGLXCREATECONTEXTATTRIBSARBPROC)glXGetProcAddress((const GLubyte*) "glXCreateContextAttribsARB"); if (!glXCreateContextAttribsARB) return false; + // Install a dummy handler to handle gracefully (aka not segfault) the support of GL version + int (*oldHandler)(Display*, XErrorEvent*) = XSetErrorHandler(&ctxErrorHandler); + // Be sure the handler is installed + XSync( m_XDisplay, false); + // Create a context int context_attribs[] = { @@ -268,9 +280,18 @@ bool GSWnd::CreateContext(int major, int minor) }; m_context = glXCreateContextAttribsARB(m_XDisplay, fbc[0], 0, true, context_attribs); - if (!m_context) return false; + // Don't forget to reinstall the older Handler + XSetErrorHandler(oldHandler); + + // Get latest error XSync( m_XDisplay, false); + + if (!m_context || ctxError) { + fprintf(stderr, "Failed to create the opengl context. Check your drivers support openGL %d.%d. Hint: opensource drivers don't\n", major, minor ); + return false; + } + return true; }