From a96cf650b967d88757bc4e550dbdbbd24dfe55cc Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Wed, 29 Oct 2014 12:22:26 +0200 Subject: Fix crash when initializing QCustom3DLabel out of context. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Task-number: QTRD-3391 Change-Id: I5c2f2b674e50e7d39bc9355ebc9bcf05f22d5a39 Reviewed-by: Tomi Korpipää --- src/datavisualization/utils/utils.cpp | 71 +++++++++++++++++++---------------- src/datavisualization/utils/utils_p.h | 1 + 2 files changed, 40 insertions(+), 32 deletions(-) (limited to 'src/datavisualization') diff --git a/src/datavisualization/utils/utils.cpp b/src/datavisualization/utils/utils.cpp index 42a1e532..685e0707 100644 --- a/src/datavisualization/utils/utils.cpp +++ b/src/datavisualization/utils/utils.cpp @@ -28,7 +28,10 @@ QT_BEGIN_NAMESPACE_DATAVISUALIZATION #define NUM_IN_POWER(y, x) for (;yfunctions()->glGetIntegerv( - GL_MAX_TEXTURE_SIZE, &maxTextureSize); - } + if (!staticsResolved) + resolveStatics(); + GLuint paddingWidth = 20; GLuint paddingHeight = 20; GLuint prePadding = 20; @@ -317,39 +319,44 @@ QQuaternion Utils::calculateRotation(const QVector3D &xyzRotations) bool Utils::isOpenGLES() { + if (!staticsResolved) + resolveStatics(); + return isES; +} + +void Utils::resolveStatics() +{ + QOpenGLContext *ctx = QOpenGLContext::currentContext(); + QWindow *dummySurface = 0; + if (!ctx) { + QSurfaceFormat surfaceFormat = qDefaultSurfaceFormat(); + dummySurface = new QWindow(); + dummySurface->setSurfaceType(QWindow::OpenGLSurface); + dummySurface->setFormat(surfaceFormat); + dummySurface->create(); + ctx = new QOpenGLContext; + ctx->setFormat(surfaceFormat); + ctx->create(); + ctx->makeCurrent(dummySurface); + } + #if defined(QT_OPENGL_ES_2) - return true; + isES = true; #elif (QT_VERSION < QT_VERSION_CHECK(5, 3, 0)) - return false; + isES = false; #else - static bool resolved = false; - static bool isES = false; - if (!resolved) { - QOpenGLContext *ctx = QOpenGLContext::currentContext(); - QWindow *dummySurface = 0; - if (!ctx) { - QSurfaceFormat surfaceFormat = qDefaultSurfaceFormat(); - dummySurface = new QWindow(); - dummySurface->setSurfaceType(QWindow::OpenGLSurface); - dummySurface->setFormat(surfaceFormat); - dummySurface->create(); - ctx = new QOpenGLContext; - ctx->setFormat(surfaceFormat); - ctx->create(); - ctx->makeCurrent(dummySurface); - } + isES = ctx->isOpenGLES(); +#endif - isES = ctx->isOpenGLES(); - resolved = true; + ctx->functions()->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize); - if (dummySurface) { - ctx->doneCurrent(); - delete ctx; - delete dummySurface; - } + if (dummySurface) { + ctx->doneCurrent(); + delete ctx; + delete dummySurface; } - return isES; -#endif + + staticsResolved = true; } QT_END_NAMESPACE_DATAVISUALIZATION diff --git a/src/datavisualization/utils/utils_p.h b/src/datavisualization/utils/utils_p.h index 1a46c731..06895bcf 100644 --- a/src/datavisualization/utils/utils_p.h +++ b/src/datavisualization/utils/utils_p.h @@ -70,6 +70,7 @@ public: static float wrapValue(float value, float min, float max); static QQuaternion calculateRotation(const QVector3D &xyzRotations); static bool isOpenGLES(); + static void resolveStatics(); private: static ParamType mapFormatCharToParamType(char formatSpec); -- cgit v1.2.3