From: Mikko Rasa Date: Sun, 12 Oct 2014 14:09:13 +0000 (+0300) Subject: Create GLContext::priv later to avoid memory leaks X-Git-Url: http://git.tdb.fi/?p=libs%2Fgui.git;a=commitdiff_plain;h=7cd7824857aa9b95a9df40e782bfc121854e1d9c Create GLContext::priv later to avoid memory leaks --- diff --git a/source/graphics/cgl/glcontext.cpp b/source/graphics/cgl/glcontext.cpp index 94b9b2f..7e06d23 100644 --- a/source/graphics/cgl/glcontext.cpp +++ b/source/graphics/cgl/glcontext.cpp @@ -19,8 +19,6 @@ struct GLContext::Private void GLContext::platform_init(const GLOptions &opts) { - priv = new Private; - vector attribs; attribs.push_back(CPF_DEPTH_SIZE); @@ -55,6 +53,7 @@ void GLContext::platform_init(const GLOptions &opts) if(!pixfmt) throw unsupported_gl_mode(opts); + priv = new Private; priv->context = create_gl_context(pixfmt); destroy_pixel_format(pixfmt); diff --git a/source/graphics/glx/glcontext.cpp b/source/graphics/glx/glcontext.cpp index a73b9c5..b3d8ed0 100644 --- a/source/graphics/glx/glcontext.cpp +++ b/source/graphics/glx/glcontext.cpp @@ -22,8 +22,6 @@ struct GLContext::Private void GLContext::platform_init(const GLOptions &opts) { - priv = new Private; - vector attribs; attribs.push_back(GLX_RGBA); @@ -60,6 +58,8 @@ void GLContext::platform_init(const GLOptions &opts) XVisualInfo *vi = glXChooseVisual(dpy, DefaultScreen(dpy), &attribs.front()); if(!vi) throw unsupported_gl_mode(opts); + + priv = new Private; priv->context = glXCreateContext(dpy, vi, 0, true); XSetWindowAttributes attr; diff --git a/source/graphics/wgl/glcontext.cpp b/source/graphics/wgl/glcontext.cpp index 964dea2..05f9533 100644 --- a/source/graphics/wgl/glcontext.cpp +++ b/source/graphics/wgl/glcontext.cpp @@ -16,8 +16,6 @@ struct GLContext::Private void GLContext::platform_init(const GLOptions &opts) { - priv = new Private; - HDC dc = GetDC(window.get_private().window); PIXELFORMATDESCRIPTOR pfd; @@ -40,6 +38,7 @@ void GLContext::platform_init(const GLOptions &opts) throw unsupported_gl_mode(opts); SetPixelFormat(dc, pf_index, &pfd); + priv = new Private; priv->context = wglCreateContext(dc); wglMakeCurrent(dc, priv->context);