summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/extras/text/qtext2dentity.cpp15
-rw-r--r--src/extras/text/qtext2dentity_p.h1
2 files changed, 15 insertions, 1 deletions
diff --git a/src/extras/text/qtext2dentity.cpp b/src/extras/text/qtext2dentity.cpp
index 10939a1e2..ae25e8ecc 100644
--- a/src/extras/text/qtext2dentity.cpp
+++ b/src/extras/text/qtext2dentity.cpp
@@ -92,10 +92,17 @@ void QText2DEntityPrivate::setScene(Qt3DCore::QScene *scene)
// Unref old glyph cache if it exists
if (m_scene != nullptr) {
+ // Ensure we don't keep reference to glyphs
+ // if we are changing the cache
+ if (m_glyphCache != nullptr)
+ clearCurrentGlyphRuns();
+
m_glyphCache = nullptr;
+
QText2DEntityPrivate::CacheEntry &entry = QText2DEntityPrivate::m_glyphCacheInstances[m_scene];
--entry.count;
if (entry.count == 0 && entry.glyphCache != nullptr) {
+
delete entry.glyphCache;
entry.glyphCache = nullptr;
}
@@ -149,7 +156,6 @@ void QText2DEntityPrivate::setCurrentGlyphRuns(const QVector<QGlyphRun> &runs)
// For each distinct texture, we need a separate DistanceFieldTextRenderer,
// for which we need vertex and index data
QHash<Qt3DRender::QAbstractTexture*, RenderData> renderData;
-
const float scale = computeActualScale();
// process glyph runs
@@ -248,6 +254,13 @@ void QText2DEntityPrivate::setCurrentGlyphRuns(const QVector<QGlyphRun> &runs)
m_currentGlyphRuns = runs;
}
+void QText2DEntityPrivate::clearCurrentGlyphRuns()
+{
+ for (int i = 0; i < m_currentGlyphRuns.size(); i++)
+ m_glyphCache->derefGlyphs(m_currentGlyphRuns[i]);
+ m_currentGlyphRuns.clear();
+}
+
void QText2DEntityPrivate::update()
{
if (m_glyphCache == nullptr)
diff --git a/src/extras/text/qtext2dentity_p.h b/src/extras/text/qtext2dentity_p.h
index 934e2087f..b98c62ce3 100644
--- a/src/extras/text/qtext2dentity_p.h
+++ b/src/extras/text/qtext2dentity_p.h
@@ -104,6 +104,7 @@ public:
float computeActualScale() const;
void setCurrentGlyphRuns(const QVector<QGlyphRun> &runs);
+ void clearCurrentGlyphRuns();
void update();
struct CacheEntry