From a561d52a8352f17f4a39bf54e0d3d9842c0d4064 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Fri, 17 Mar 2023 15:03:54 +0100 Subject: [PATCH] Add QImage null check when QOpenGLTexture converts ...the image to RGBA8888. Just mirror the first null check that is done for the user-provided QImage. The same should be done for the result of convertToFormat(). Pick-to: 6.5 6.5 6.2 5.15 Fixes: QTBUG-68884 Change-Id: I77091d7a2bc6e32d2aa292dc7650c1af091fcec1 Reviewed-by: Andy Nichols --- src/opengl/qopengltexture.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/opengl/qopengltexture.cpp b/src/opengl/qopengltexture.cpp index f7053be6ddc..3b8e14490b3 100644 --- a/src/opengl/qopengltexture.cpp +++ b/src/opengl/qopengltexture.cpp @@ -3631,6 +3631,12 @@ void QOpenGLTexture::setData(const QImage& image, MipMapGeneration genMipMaps) return; } + QImage glImage = image.convertToFormat(QImage::Format_RGBA8888); + if (glImage.isNull()) { + qWarning("QOpenGLTexture::setData() failed to convert image"); + return; + } + if (context->isOpenGLES() && context->format().majorVersion() < 3) setFormat(QOpenGLTexture::RGBAFormat); else @@ -3641,7 +3647,6 @@ void QOpenGLTexture::setData(const QImage& image, MipMapGeneration genMipMaps) allocateStorage(QOpenGLTexture::RGBA, QOpenGLTexture::UInt8); // Upload pixel data and generate mipmaps - QImage glImage = image.convertToFormat(QImage::Format_RGBA8888); QOpenGLPixelTransferOptions uploadOptions; uploadOptions.setAlignment(1); setData(0, QOpenGLTexture::RGBA, QOpenGLTexture::UInt8, glImage.constBits(), &uploadOptions);