summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire@kdab.com>2023-02-13 07:46:07 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2023-02-14 08:16:55 +0000
commit00eea450030f549af227a7db3cbe37e54e7b1410 (patch)
tree2789a6f138086b54c8580d99e5781dbb95783e17
parent4b8b02c20c56f8a0684c056148353e91d9df568a (diff)
QDistanceFieldCache: fix QTextureAtlas dangling pointer
Note: already merged in 5.15 Change-Id: If968714f1ca4869e9c607224b537e355b4a6f0dd Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Paul Lemire <paul.lemire@kdab.com> (cherry picked from commit b7e398620a5b467e5205722da5314938d1430f8e) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/extras/text/qdistancefieldglyphcache.cpp10
-rw-r--r--tests/auto/extras/qtext2dentity/tst_qtext2dentity.cpp2
2 files changed, 9 insertions, 3 deletions
diff --git a/src/extras/text/qdistancefieldglyphcache.cpp b/src/extras/text/qdistancefieldglyphcache.cpp
index 3c0ab4d16..1294cf53a 100644
--- a/src/extras/text/qdistancefieldglyphcache.cpp
+++ b/src/extras/text/qdistancefieldglyphcache.cpp
@@ -162,13 +162,14 @@ StoredGlyph DistanceFieldFont::refGlyph(quint32 glyph)
// scenarios
const int size = m_doubleGlyphResolution ? 512 : 256;
- QTextureAtlas *atlas = new QTextureAtlas(m_parentNode);
+ QTextureAtlas *atlas = new QTextureAtlas();
atlas->setWidth(size);
atlas->setHeight(size);
atlas->setFormat(Qt3DRender::QAbstractTexture::R8_UNorm);
atlas->setPixelFormat(QOpenGLTexture::Red);
atlas->setMinificationFilter(Qt3DRender::QAbstractTexture::Linear);
atlas->setMagnificationFilter(Qt3DRender::QAbstractTexture::Linear);
+ atlas->setParent(m_parentNode);
m_atlasses << atlas;
if (!storedGlyph.addToTextureAtlas(atlas))
@@ -201,7 +202,12 @@ void DistanceFieldFont::derefGlyph(quint32 glyph)
Q_ASSERT(m_atlasses.contains(atlas));
m_atlasses.removeAll(atlas);
- delete atlas;
+
+ // This function might have been called as a result of destroying
+ // the scene root which traverses the entire scene tree. Calling
+ // delete on the atlas here could lead to dangling pointers in the
+ // least of children being traversed for destruction.
+ atlas->deleteLater();
}
m_glyphs.erase(it);
diff --git a/tests/auto/extras/qtext2dentity/tst_qtext2dentity.cpp b/tests/auto/extras/qtext2dentity/tst_qtext2dentity.cpp
index aec1e9315..4bcb39276 100644
--- a/tests/auto/extras/qtext2dentity/tst_qtext2dentity.cpp
+++ b/tests/auto/extras/qtext2dentity/tst_qtext2dentity.cpp
@@ -44,7 +44,7 @@ void tst_qtext2dentity::checkChangeArbiter()
auto atlases = lookupNodeByClassName(rootEntity.data(), "Qt3DExtras::QTextureAtlas");
QVERIFY(atlases.size() == 1);
auto atlas = atlases[0];
- QTRY_VERIFY(Qt3DCore::QNodePrivate::get(atlas)->m_changeArbiter);
+ QVERIFY(Qt3DCore::QNodePrivate::get(atlas)->m_changeArbiter);
}
QTEST_MAIN(tst_qtext2dentity)