Skip to content

Commit a0a2f3b

Browse files
eskilblomfeldtQt Cherry-pick Bot
authored andcommitted
Fix crash in distance field cache with some glyphs
The size of a distance field for a glyph is calculated as: w = ceil((boundingRect.width() + 2 * margin) / scale) h = ceil((boundingRect.height() + 2 * margin) / scale) In addition, the RHI-specific cache subclass adds padding on the outside of this. This was done in multiple places, both in Qt Base and Qt Declarative. If they got out of sync, then we would crash, since the distance field size is expected to match up with the allocated rect in the cache's texture. For the most part this worked since the formula was copied everywhere, but since the QDistanceField does a translate() on the path before getting the bounding rect, we could get a result which was off by a very small amount (0.0000000000000071 in this case). A qCeil() turned this into an off-by-one, and memory corruption occurred. To avoid duplicating this formula in both Qt Base and Qt Declarative, we explicitly pass in the size we expect when creating the QDistanceField. Pick-to: 6.2 5.15 Fixes: QTBUG-124572 Change-Id: I6bb8ab4db17b43fe8ddf9db35de5b7d51ccb54de Reviewed-by: Eirik Aavitsland <[email protected]> (cherry picked from commit 2370cb0) Reviewed-by: Qt Cherry-pick Bot <[email protected]> (cherry picked from commit e180e53) (cherry picked from commit a1c733f)
1 parent a7212f9 commit a0a2f3b

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/quick/scenegraph/qsgadaptationlayer.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,12 @@ void QSGDistanceFieldGlyphCache::update()
166166
distanceFields.reserve(pendingGlyphsSize);
167167
for (int i = 0; i < pendingGlyphsSize; ++i) {
168168
GlyphData &gd = glyphData(m_pendingGlyphs.at(i));
169-
distanceFields.append(QDistanceField(gd.path,
169+
170+
QSize size = QSize(qCeil(gd.texCoord.width + gd.texCoord.xMargin * 2),
171+
qCeil(gd.texCoord.height + gd.texCoord.yMargin * 2));
172+
173+
distanceFields.append(QDistanceField(size,
174+
gd.path,
170175
m_pendingGlyphs.at(i),
171176
m_doubleGlyphResolution));
172177
gd.path = QPainterPath(); // no longer needed, so release memory used by the painter path

0 commit comments

Comments
 (0)