summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/gui/opengl/qopenglpaintengine.cpp1
-rw-r--r--src/gui/opengl/qopengltextureglyphcache_p.h5
-rw-r--r--tests/auto/widgets/widgets/qopenglwidget/tst_qopenglwidget.cpp54
3 files changed, 60 insertions, 0 deletions
diff --git a/src/gui/opengl/qopenglpaintengine.cpp b/src/gui/opengl/qopenglpaintengine.cpp
index 3d1c362275..6a89089f18 100644
--- a/src/gui/opengl/qopenglpaintengine.cpp
+++ b/src/gui/opengl/qopenglpaintengine.cpp
@@ -1741,6 +1741,7 @@ void QOpenGL2PaintEngineExPrivate::drawCachedGlyphs(QFontEngine::GlyphFormat gly
// we may have to re-bind brush textures after filling in the cache.
brushTextureDirty = (QT_BRUSH_TEXTURE_UNIT == glypchCacheTextureUnit);
}
+ cache->setPaintEnginePrivate(nullptr);
}
if (cache->width() == 0 || cache->height() == 0)
diff --git a/src/gui/opengl/qopengltextureglyphcache_p.h b/src/gui/opengl/qopengltextureglyphcache_p.h
index 0b7b5f6082..598cb00ee5 100644
--- a/src/gui/opengl/qopengltextureglyphcache_p.h
+++ b/src/gui/opengl/qopengltextureglyphcache_p.h
@@ -152,6 +152,11 @@ public:
void clear();
+ QOpenGL2PaintEngineExPrivate *paintEnginePrivate() const
+ {
+ return pex;
+ }
+
private:
void setupVertexAttribs();
diff --git a/tests/auto/widgets/widgets/qopenglwidget/tst_qopenglwidget.cpp b/tests/auto/widgets/widgets/qopenglwidget/tst_qopenglwidget.cpp
index db125f6644..21c9f41646 100644
--- a/tests/auto/widgets/widgets/qopenglwidget/tst_qopenglwidget.cpp
+++ b/tests/auto/widgets/widgets/qopenglwidget/tst_qopenglwidget.cpp
@@ -30,6 +30,7 @@
#include <QtGui/QOpenGLFunctions>
#include <QtGui/QPainter>
#include <QtGui/QScreen>
+#include <QtGui/QStaticText>
#include <QtWidgets/QDesktopWidget>
#include <QtWidgets/QGraphicsView>
#include <QtWidgets/QGraphicsScene>
@@ -40,6 +41,8 @@
#include <QtTest/QtTest>
#include <QSignalSpy>
#include <private/qguiapplication_p.h>
+#include <private/qstatictext_p.h>
+#include <private/qopengltextureglyphcache_p.h>
#include <qpa/qplatformintegration.h>
class tst_QOpenGLWidget : public QObject
@@ -64,6 +67,10 @@ private slots:
void stackWidgetOpaqueChildIsVisible();
void offscreen();
void offscreenThenOnscreen();
+
+#ifdef QT_BUILD_INTERNAL
+ void staticTextDanglingPointer();
+#endif
};
void tst_QOpenGLWidget::initTestCase()
@@ -675,6 +682,53 @@ void tst_QOpenGLWidget::offscreenThenOnscreen()
QVERIFY(image.pixel(30, 40) == qRgb(0, 0, 255));
}
+class StaticTextPainterWidget : public QOpenGLWidget
+{
+public:
+ StaticTextPainterWidget(QWidget *parent = nullptr)
+ : QOpenGLWidget(parent)
+ {
+ }
+
+ void paintEvent(QPaintEvent *)
+ {
+ QPainter p(this);
+ text.setText(QStringLiteral("test"));
+ p.drawStaticText(0, 0, text);
+
+ ctx = QOpenGLContext::currentContext();
+ }
+
+ QStaticText text;
+ QOpenGLContext *ctx;
+};
+
+#ifdef QT_BUILD_INTERNAL
+void tst_QOpenGLWidget::staticTextDanglingPointer()
+{
+ QWidget w;
+ StaticTextPainterWidget *glw = new StaticTextPainterWidget(&w);
+ w.resize(640, 480);
+ glw->resize(320, 200);
+ w.show();
+
+ QVERIFY(QTest::qWaitForWindowExposed(&w));
+ QStaticTextPrivate *d = QStaticTextPrivate::get(&glw->text);
+
+ QCOMPARE(d->itemCount, 1);
+ QFontEngine *fe = d->items->fontEngine();
+
+ for (int i = QFontEngine::Format_None; i <= QFontEngine::Format_ARGB; ++i) {
+ QOpenGLTextureGlyphCache *cache =
+ (QOpenGLTextureGlyphCache *) fe->glyphCache(glw->ctx,
+ QFontEngine::GlyphFormat(i),
+ QTransform());
+ if (cache != nullptr)
+ QCOMPARE(cache->paintEnginePrivate(), nullptr);
+ }
+}
+#endif
+
QTEST_MAIN(tst_QOpenGLWidget)
#include "tst_qopenglwidget.moc"