From 91d39de64562fa9feb83374989293f68beec8366 Mon Sep 17 00:00:00 2001 From: "gregory.hainaut" Date: Sun, 30 Jun 2013 15:27:50 +0000 Subject: [PATCH] gsdx ogl: fix crash when pause/resume with EGL (opensource driver) git-svn-id: http://pcsx2.googlecode.com/svn/trunk@5690 96395faa-99c1-11dd-bbfe-3dabce05a288 --- plugins/GSdx/GS.cpp | 34 +++++++++++++++++++++------------- plugins/GSdx/GSWndEGL.cpp | 1 + plugins/GSdx/GSWndOGL.cpp | 5 ++--- 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/plugins/GSdx/GS.cpp b/plugins/GSdx/GS.cpp index 14e4476bc8..022f128388 100644 --- a/plugins/GSdx/GS.cpp +++ b/plugins/GSdx/GS.cpp @@ -360,22 +360,30 @@ static int _GSopen(void** dsp, char* title, int renderer, int threads = -1) s_gs->SetMultithreaded(true); #ifdef _LINUX - for(uint32 i = 0; i < 2; i++) { - try - { - if (wnd[i] == NULL) continue; + if (s_gs->m_wnd) { + // A window was already attached to s_gs so we also + // need to restore the window state (Attach) + s_gs->m_wnd->Attach((void*)((uint32*)(dsp)+1), false); + } else { + // No window found, try to attach a GLX win and retry + // with EGL win if failed. + for(uint32 i = 0; i < 2; i++) { + try + { + if (wnd[i] == NULL) continue; - wnd[i]->Attach((void*)((uint32*)(dsp)+1), false); - s_gs->m_wnd = wnd[i]; + wnd[i]->Attach((void*)((uint32*)(dsp)+1), false); + s_gs->m_wnd = wnd[i]; - if (i == 0) delete wnd[1]; + if (i == 0) delete wnd[1]; - break; - } - catch (GSDXRecoverableError) - { - wnd[i]->Detach(); - delete wnd[i]; + break; + } + catch (GSDXRecoverableError) + { + wnd[i]->Detach(); + delete wnd[i]; + } } } if (s_gs->m_wnd == NULL) diff --git a/plugins/GSdx/GSWndEGL.cpp b/plugins/GSdx/GSWndEGL.cpp index 0ced8f4ee6..0bb97bd05d 100644 --- a/plugins/GSdx/GSWndEGL.cpp +++ b/plugins/GSdx/GSWndEGL.cpp @@ -267,6 +267,7 @@ void GSWndEGL::HideFrame() void GSWndEGL::CloseEGLDisplay() { + eglReleaseThread(); eglTerminate(m_eglDisplay); } diff --git a/plugins/GSdx/GSWndOGL.cpp b/plugins/GSdx/GSWndOGL.cpp index e74123ee99..6063b91c17 100644 --- a/plugins/GSdx/GSWndOGL.cpp +++ b/plugins/GSdx/GSWndOGL.cpp @@ -63,8 +63,6 @@ void GSWndOGL::CreateContext(int major, int minor) if (!fbc || fbcount < 1) { throw GSDXRecoverableError(); } - XFree(fbc); - GLXFBConfig fbc_cp = fbc[0]; PFNGLXCREATECONTEXTATTRIBSARBPROC glX_CreateContextAttribsARB = (PFNGLXCREATECONTEXTATTRIBSARBPROC)glXGetProcAddress((const GLubyte*) "glXCreateContextAttribsARB"); if (!glX_CreateContextAttribsARB) { @@ -88,7 +86,8 @@ void GSWndOGL::CreateContext(int major, int minor) None }; - m_context = glX_CreateContextAttribsARB(m_NativeDisplay, fbc_cp, 0, true, context_attribs); + m_context = glX_CreateContextAttribsARB(m_NativeDisplay, fbc[0], 0, true, context_attribs); + XFree(fbc); // Don't forget to reinstall the older Handler XSetErrorHandler(oldHandler);