summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire@kdab.com>2023-02-13 07:46:07 +0100
committerPaul Lemire <paul.lemire@kdab.com>2023-02-14 07:39:46 +0100
commitb7e398620a5b467e5205722da5314938d1430f8e (patch)
treeed39b306d785db76868af7ecd01242460f0722c4
parent7c853a3aa742a9500266e9e41b6702f05ae1a297 (diff)
downloadqt3d-b7e398620a5b467e5205722da5314938d1430f8e.tar.gz
QDistanceFieldCache: fix QTextureAtlas dangling pointer
Note: already merged in 5.15 Pick-to: 6.5 6.4 6.2 Change-Id: If968714f1ca4869e9c607224b537e355b4a6f0dd Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
-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)