From 672f7dfdcd00d124cd0f973e04e3e2d6445d5483 Mon Sep 17 00:00:00 2001 From: Juha Turunen Date: Tue, 8 Dec 2015 00:51:54 -0800 Subject: Fix a crash when calling QOpenGLTexture::setData with a null QImage. Change-Id: Idf8ae00cff6929114b38dcb003c259c83a11dbaa Reviewed-by: Laszlo Agocs --- src/gui/opengl/qopengltexture.cpp | 6 ++++++ tests/auto/gui/qopengl/tst_qopengl.cpp | 15 ++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/gui/opengl/qopengltexture.cpp b/src/gui/opengl/qopengltexture.cpp index 5271826015..c58ddbd71e 100644 --- a/src/gui/opengl/qopengltexture.cpp +++ b/src/gui/opengl/qopengltexture.cpp @@ -3050,6 +3050,12 @@ void QOpenGLTexture::setData(const QImage& image, MipMapGeneration genMipMaps) qWarning("QOpenGLTexture::setData() requires a valid current context"); return; } + + if (image.isNull()) { + qWarning("QOpenGLTexture::setData() tried to set a null image"); + return; + } + if (context->isOpenGLES() && context->format().majorVersion() < 3) setFormat(QOpenGLTexture::RGBAFormat); else diff --git a/tests/auto/gui/qopengl/tst_qopengl.cpp b/tests/auto/gui/qopengl/tst_qopengl.cpp index 8c6c28b492..3e66bcbf70 100644 --- a/tests/auto/gui/qopengl/tst_qopengl.cpp +++ b/tests/auto/gui/qopengl/tst_qopengl.cpp @@ -39,6 +39,7 @@ #include #include #include +#include #include #include #include @@ -97,8 +98,8 @@ private slots: void textureblitterFullTargetRectTransform(); void textureblitterPartTargetRectTransform(); void defaultSurfaceFormat(); - void imageFormatPainting(); + void nullTextureInitializtion(); #ifdef USE_GLX void glxContextWrap(); @@ -1367,6 +1368,18 @@ void tst_QOpenGL::bufferMapRange() ctx->doneCurrent(); } +void tst_QOpenGL::nullTextureInitializtion() +{ + QScopedPointer surface(createSurface(QSurface::Window)); + QOpenGLContext ctx; + ctx.create(); + ctx.makeCurrent(surface.data()); + + QImage i; + QOpenGLTexture t(i); + QVERIFY(!t.isCreated()); +} + QTEST_MAIN(tst_QOpenGL) #include "tst_qopengl.moc" -- cgit v1.2.3