gsdx wgl: drop GL2.0 context and avoid a context leak

Namely detach/delete context before throwing
This commit is contained in:
Gregory Hainaut 2017-02-17 19:20:42 +01:00
parent cdb71101a1
commit 674d22321a
1 changed files with 40 additions and 39 deletions

View File

@ -47,12 +47,14 @@ LRESULT CALLBACK GSWndWGL::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARA
void GSWndWGL::CreateContext(int major, int minor) void GSWndWGL::CreateContext(int major, int minor)
{ {
if ( !m_NativeDisplay || !m_NativeWindow ) if (!m_NativeDisplay || !m_NativeWindow)
{ {
fprintf( stderr, "Wrong display/window\n" ); fprintf( stderr, "Wrong display/window\n" );
exit(1); exit(1);
} }
ASSERT(major >= 3);
// GL2 context are quite easy but we need GL3 which is another painful story... // GL2 context are quite easy but we need GL3 which is another painful story...
m_context = wglCreateContext(m_NativeDisplay); m_context = wglCreateContext(m_NativeDisplay);
if (!m_context) { if (!m_context) {
@ -63,7 +65,6 @@ void GSWndWGL::CreateContext(int major, int minor)
// FIXME test it // FIXME test it
// Note: albeit every tutorial said that we need an opengl context to use the GL function wglCreateContextAttribsARB // Note: albeit every tutorial said that we need an opengl context to use the GL function wglCreateContextAttribsARB
// On linux it works without the extra temporary context, not sure the limitation still applied // On linux it works without the extra temporary context, not sure the limitation still applied
if (major >= 3) {
AttachContext(); AttachContext();
// Create a context // Create a context
@ -98,18 +99,18 @@ void GSWndWGL::CreateContext(int major, int minor)
context_attribs[2*2+1] = 0; context_attribs[2*2+1] = 0;
context30 = wglCreateContextAttribsARB(m_NativeDisplay, NULL, context_attribs); context30 = wglCreateContextAttribsARB(m_NativeDisplay, NULL, context_attribs);
if (!context30) {
fprintf(stderr, "Failed to create a 3.x context with compatible flags\n");
throw GSDXRecoverableError();
}
} }
DetachContext(); DetachContext();
wglDeleteContext(m_context); wglDeleteContext(m_context);
if (!context30) {
fprintf(stderr, "Failed to create a 3.x context with compatible flags\n");
throw GSDXRecoverableError();
}
m_context = context30; m_context = context30;
fprintf(stderr, "3.x GL context successfully created\n"); fprintf(stderr, "3.x GL context successfully created\n");
}
} }
void GSWndWGL::AttachContext() void GSWndWGL::AttachContext()