Fix crash in OpenGL pyramid example if context creation fails

Initialize context pointers to null so that we don't delete uninitialized junk
later.

See #16910.

Closes https://github.com/wxWidgets/wxWidgets/pull/233
This commit is contained in:
Maarten Bent
2016-02-26 12:35:50 +01:00
committed by Vadim Zeitlin
parent 5ab459e4c7
commit e2fb055329
3 changed files with 7 additions and 1 deletions

View File

@@ -552,6 +552,7 @@ wxIMPLEMENT_CLASS(wxGLContext, wxObject);
wxGLContext::wxGLContext(wxGLCanvas *win, wxGLContext::wxGLContext(wxGLCanvas *win,
const wxGLContext *other, const wxGLContext *other,
const wxGLContextAttrs *ctxAttrs) const wxGLContextAttrs *ctxAttrs)
: m_glContext(NULL)
{ {
const int* contextAttribs = NULL; const int* contextAttribs = NULL;
bool needsARB = false; bool needsARB = false;
@@ -614,7 +615,10 @@ wxGLContext::wxGLContext(wxGLCanvas *win,
wxGLContext::~wxGLContext() wxGLContext::~wxGLContext()
{ {
// note that it's ok to delete the context even if it's the current one // note that it's ok to delete the context even if it's the current one
wglDeleteContext(m_glContext); if ( m_glContext )
{
wglDeleteContext(m_glContext);
}
} }
bool wxGLContext::SetCurrent(const wxGLCanvas& win) const bool wxGLContext::SetCurrent(const wxGLCanvas& win) const

View File

@@ -359,6 +359,7 @@ wxGLAttributes& wxGLAttributes::Defaults()
wxGLContext::wxGLContext(wxGLCanvas *win, wxGLContext::wxGLContext(wxGLCanvas *win,
const wxGLContext *other, const wxGLContext *other,
const wxGLContextAttrs *ctxAttrs) const wxGLContextAttrs *ctxAttrs)
: m_glContext(NULL)
{ {
const int* contextAttribs = NULL; const int* contextAttribs = NULL;
int ctxSize = 0; int ctxSize = 0;

View File

@@ -454,6 +454,7 @@ wxIMPLEMENT_CLASS(wxGLContext, wxObject);
wxGLContext::wxGLContext(wxGLCanvas *win, wxGLContext::wxGLContext(wxGLCanvas *win,
const wxGLContext *other, const wxGLContext *other,
const wxGLContextAttrs *ctxAttrs) const wxGLContextAttrs *ctxAttrs)
: m_glContext(NULL)
{ {
const int* contextAttribs = NULL; const int* contextAttribs = NULL;
Bool x11Direct = True; Bool x11Direct = True;