diff options
| author | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io> | 2023-11-27 15:13:21 +0100 |
|---|---|---|
| committer | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io> | 2023-11-28 09:42:50 +0100 |
| commit | 2bc7d894a7e7380270f057433e7ebefa32edbed3 (patch) | |
| tree | c16e13281329f93fbccfee5f072ddad6f59f3b3f | |
| parent | ed065f85863392a4dd253dd72737414590d6f958 (diff) | |
Fix possible crash when using CurveRenderer text
The curve renderer would keep references to its cache, which
could be invalid if the font database had been purged.
For the distance field renderer we handle this by never purging
caches that are in use, but we don't really need such a mechanism
with the CurveRenderer, since we don't need to keep any data
around for the actual rendering later (like the textures in the
other caches).
Instead, we just look up the cache when we need it, if it has
been purged in the mean time, it's just re-created.
Change-Id: I0c2a84f3176787f94c599b65296b9d87d2e28858
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
| -rw-r--r-- | src/quick/scenegraph/qsgcurveglyphnode.cpp | 30 | ||||
| -rw-r--r-- | src/quick/scenegraph/qsgcurveglyphnode_p.h | 1 |
2 files changed, 14 insertions, 17 deletions
diff --git a/src/quick/scenegraph/qsgcurveglyphnode.cpp b/src/quick/scenegraph/qsgcurveglyphnode.cpp index f68c116554..c5252083d3 100644 --- a/src/quick/scenegraph/qsgcurveglyphnode.cpp +++ b/src/quick/scenegraph/qsgcurveglyphnode.cpp @@ -68,9 +68,6 @@ void QSGCurveGlyphNode::setGlyphs(const QPointF &position, const QGlyphRun &glyp m_fontSize = font.pixelSize(); m_position = QPointF(position.x(), position.y() - font.ascent()); - m_curveGlyphAtlas = m_context->curveGlyphAtlas(font); - - m_curveGlyphAtlas->populate(glyphs.glyphIndexes()); m_dirtyGeometry = true; @@ -102,14 +99,15 @@ void QSGCurveGlyphNode::updateGeometry() delete m_styleNode; m_styleNode = nullptr; - Q_ASSERT(m_curveGlyphAtlas != nullptr); + QSGCurveGlyphAtlas *curveGlyphAtlas = m_context->curveGlyphAtlas(m_glyphs.rawFont()); + curveGlyphAtlas->populate(m_glyphs.glyphIndexes()); m_glyphNode = new QSGCurveFillNode; m_glyphNode->setColor(m_color); QPointF offset; - float fontScale = float(m_fontSize / m_curveGlyphAtlas->fontSize()); + float fontScale = float(m_fontSize / curveGlyphAtlas->fontSize()); QSGCurveFillNode *raisedSunkenStyleNode = nullptr; QSGCurveStrokeNode *outlineNode = nullptr; if (m_style == QQuickText::Raised || m_style == QQuickText::Sunken) { @@ -132,23 +130,23 @@ void QSGCurveGlyphNode::updateGeometry() for (qsizetype i = 0; i < indexes.size(); ++i) { if (i == 0) m_baseLine = positions.at(i); - m_curveGlyphAtlas->addGlyph(m_glyphNode, - indexes.at(i), - m_position + positions.at(i), - m_fontSize); + curveGlyphAtlas->addGlyph(m_glyphNode, + indexes.at(i), + m_position + positions.at(i), + m_fontSize); if (raisedSunkenStyleNode != nullptr) { - m_curveGlyphAtlas->addGlyph(raisedSunkenStyleNode, - indexes.at(i), - m_position + positions.at(i) + offset, - m_fontSize); + curveGlyphAtlas->addGlyph(raisedSunkenStyleNode, + indexes.at(i), + m_position + positions.at(i) + offset, + m_fontSize); } if (outlineNode != nullptr) { // Since the stroke node will scale everything by fontScale internally (the // shader does not support pre-transforming the vertices), we have to also first // do the inverse scale on the glyph position to get the correct position. - m_curveGlyphAtlas->addStroke(outlineNode, - indexes.at(i), - (m_position + positions.at(i)) / fontScale); + curveGlyphAtlas->addStroke(outlineNode, + indexes.at(i), + (m_position + positions.at(i)) / fontScale); } } diff --git a/src/quick/scenegraph/qsgcurveglyphnode_p.h b/src/quick/scenegraph/qsgcurveglyphnode_p.h index 862fdbf70a..9d1c4e43bb 100644 --- a/src/quick/scenegraph/qsgcurveglyphnode_p.h +++ b/src/quick/scenegraph/qsgcurveglyphnode_p.h @@ -43,7 +43,6 @@ public: private: QSGRenderContext *m_context; - QSGCurveGlyphAtlas *m_curveGlyphAtlas = nullptr; QSGGeometry m_geometry; QColor m_color = Qt::black; |
