From a05eb132416fcce8eb6a9fb240d0867796ed9deb Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Thu, 20 Jun 2019 10:26:38 +0200 Subject: distancefieldgenerator: Fix crash with multiple textures We need to make sure the allocated area starts at (0,0), since we allocate a texture at [width x height], and this would be too small if it did not also account for possible gaps at the top of the cache. This happens because glyphs may sometimes end up at the edge between two textures, in which case we will reserve space for them in the second of the two even though this is not needed. So this is a deficiency in the cache logic itself, but we need to at least make sure it does not crash. [ChangeLog][distancefieldgenerator] Fixed possible crash when generating large number of glyphs with a small texture size. Task-number: QTBUG-76188 Task-number: QTBUG-76528 Change-Id: I84c87c72985f5b621d120e7526cfe071555fa7f8 Reviewed-by: Simon Hausmann --- src/distancefieldgenerator/mainwindow.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/distancefieldgenerator/mainwindow.cpp b/src/distancefieldgenerator/mainwindow.cpp index 94f5c8ebb..3717330b4 100644 --- a/src/distancefieldgenerator/mainwindow.cpp +++ b/src/distancefieldgenerator/mainwindow.cpp @@ -488,14 +488,14 @@ QByteArray MainWindow::createSfntTable() break; glyphData.textureIndex = rect.y() / textureSize; - if (glyphData.textureIndex >= allocatedAreaPerTexture.size()) - allocatedAreaPerTexture.resize(glyphData.textureIndex + 1); + while (glyphData.textureIndex >= allocatedAreaPerTexture.size()) + allocatedAreaPerTexture.append(QRect(0, 0, 1, 1)); + allocatedAreaPerTexture[glyphData.textureIndex] |= QRect(rect.x(), rect.y() % textureSize, rect.width(), rect.height()); - glyphData.texCoord.xMargin = QT_DISTANCEFIELD_RADIUS(m_model->doubleGlyphResolution()) / qreal(QT_DISTANCEFIELD_SCALE(m_model->doubleGlyphResolution())); glyphData.texCoord.yMargin = QT_DISTANCEFIELD_RADIUS(m_model->doubleGlyphResolution()) / qreal(QT_DISTANCEFIELD_SCALE(m_model->doubleGlyphResolution())); glyphData.texCoord.x = rect.x() + padding; -- cgit v1.2.3