From 14a896cf6b8b67a8d83a6204737249afa9ecd220 Mon Sep 17 00:00:00 2001 From: Trond Kjernaasen Date: Mon, 28 Sep 2009 16:52:04 +0200 Subject: Fixed a crash in the boxes demo when using -graphicssystem opengl. Several problems: 1. The demo leaked the scene contents, which caused cleanup problems. 2. The QGLContext::currentContext() could be changed behind Qt's back under Windows (the temp contexts never reset the current context). 3. QGLFormat::openGLVersionFlags() function would return uninitialized flags if the QGLWidget constructor happened to call qt_gl_preferGL2Engine(). Reviewed-by: Kim --- demos/boxes/main.cpp | 7 ++++--- src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp | 2 +- src/opengl/qgl.cpp | 2 +- src/opengl/qgl_win.cpp | 6 ++++++ 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/demos/boxes/main.cpp b/demos/boxes/main.cpp index 557afc9..957f183 100644 --- a/demos/boxes/main.cpp +++ b/demos/boxes/main.cpp @@ -68,7 +68,7 @@ protected: inline bool matchString(const char *extensionString, const char *subString) { int subStringLength = strlen(subString); - return (strncmp(extensionString, subString, subStringLength) == 0) + return (strncmp(extensionString, subString, subStringLength) == 0) && ((extensionString[subStringLength] == ' ') || (extensionString[subStringLength] == '\0')); } @@ -137,11 +137,12 @@ int main(int argc, char **argv) "This demo can be GPU and CPU intensive and may\n" "work poorly or not at all on your system."); + widget->makeCurrent(); // The current context must be set before calling Scene's constructor + Scene scene(1024, 768, maxTextureSize); GraphicsView view; view.setViewport(widget); view.setViewportUpdateMode(QGraphicsView::FullViewportUpdate); - widget->makeCurrent(); // The current context must be set before calling Scene's constructor - view.setScene(new Scene(1024, 768, maxTextureSize)); + view.setScene(&scene); view.show(); return app.exec(); diff --git a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp index 119c89d..7e45fd9 100644 --- a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp +++ b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp @@ -129,7 +129,7 @@ public Q_SLOTS: // since the context holding the texture is shared, and // about to be destroyed, we have to transfer ownership // of the texture to one of the share contexts - ctx = const_cast(shares.at(0)); + ctx = const_cast((ctx == shares.at(0)) ? shares.at(1) : shares.at(0)); } } } diff --git a/src/opengl/qgl.cpp b/src/opengl/qgl.cpp index 97a4a73..0ad6772 100644 --- a/src/opengl/qgl.cpp +++ b/src/opengl/qgl.cpp @@ -1245,11 +1245,11 @@ QGLFormat::OpenGLVersionFlags QGLFormat::openGLVersionFlags() if (cachedDefault) { return defaultVersionFlags; } else { - cachedDefault = true; if (!hasOpenGL()) return defaultVersionFlags; dummy = new QGLWidget; dummy->makeCurrent(); // glGetString() needs a current context + cachedDefault = true; } } diff --git a/src/opengl/qgl_win.cpp b/src/opengl/qgl_win.cpp index 2f9e225..5b5820a 100644 --- a/src/opengl/qgl_win.cpp +++ b/src/opengl/qgl_win.cpp @@ -660,6 +660,8 @@ public: int dmy_pf = ChoosePixelFormat(dmy_pdc, &dmy_pfd); SetPixelFormat(dmy_pdc, dmy_pf, &dmy_pfd); dmy_rc = wglCreateContext(dmy_pdc); + old_dc = wglGetCurrentDC(); + old_context = wglGetCurrentContext(); wglMakeCurrent(dmy_pdc, dmy_rc); } @@ -668,10 +670,14 @@ public: wglDeleteContext(dmy_rc); ReleaseDC(dmy_id, dmy_pdc); DestroyWindow(dmy_id); + if (old_dc && old_context) + wglMakeCurrent(old_dc, old_context); } HDC dmy_pdc; HGLRC dmy_rc; + HDC old_dc; + HGLRC old_context; WId dmy_id; }; -- cgit v0.12