summaryrefslogtreecommitdiffstats
path: root/src/runtimerender/Qt3DSDistanceFieldGlyphCache_p.h
diff options
context:
space:
mode:
authorEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>2022-06-15 09:50:57 +0200
committerEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>2022-06-16 10:49:38 +0200
commit6d11ee1b0511e9985f1b88a6aa660f1bc0fe2e09 (patch)
tree1b1a2f866b8e4a8d761b07fd911dc4efd6cfd8d8 /src/runtimerender/Qt3DSDistanceFieldGlyphCache_p.h
parent427fddb50d43aa21a90fc7356ee3cdd8a908df56 (diff)
Fix crash when expanding glyph cache beyond one texture
The textureInfo() function was returning pointers to the m_textures array, which would then be stored in the m_glyphTextures map and other places in the renderer. Then the function then later resized it, the renderer would be riddled with dangling pointers and crash pretty quickly. There is a preset maximum texture count, so we just make sure the array is the correct size to begin with and never resize it. In addition, this contains a port of 46d72a117df642135718b38995346267312c4808 and 9a53834f1e7fce2fc3b1ecc2a311faedbc371d37 from Qt Quick. Note: Glyph recycling does not seem to work, so you may end up running out of cache space. However, it will no longer crash, but glyphs will be missing instead. Fixes: QT3DS-4235 Change-Id: I7d9707ff95ac0838e7e6574714a06ac1c23986fa Reviewed-by: Janne Koskinen <janne.p.koskinen@qt.io>
Diffstat (limited to 'src/runtimerender/Qt3DSDistanceFieldGlyphCache_p.h')
-rw-r--r--src/runtimerender/Qt3DSDistanceFieldGlyphCache_p.h8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/runtimerender/Qt3DSDistanceFieldGlyphCache_p.h b/src/runtimerender/Qt3DSDistanceFieldGlyphCache_p.h
index fb4826e..2eca726 100644
--- a/src/runtimerender/Qt3DSDistanceFieldGlyphCache_p.h
+++ b/src/runtimerender/Qt3DSDistanceFieldGlyphCache_p.h
@@ -54,10 +54,10 @@ class Q3DSDistanceFieldGlyphCache : public QSGDistanceFieldGlyphCache
{
public:
struct TextureInfo {
- qt3ds::render::NVRenderTexture2D *texture;
+ qt3ds::render::NVRenderTexture2D *texture = nullptr;
int padding = -1;
- QRect allocatedArea;
+ QRect allocatedArea = QRect(0, 0, 1, 1);
QImage copy;
};
@@ -84,12 +84,12 @@ private:
bool loadPregeneratedCache(const QRawFont &font);
TextureInfo *textureInfo(int index) const;
- int maxTextureSize() const;
void resizeTexture(TextureInfo *info, int width, int height);
void setTextureData(qt3ds::render::NVRenderTexture2D *texture, QImage &image);
QSGAreaAllocator *m_areaAllocator = nullptr;
- int m_maxTextureSize = 0;
+ int m_maxTextureWidth = 0;
+ int m_maxTextureHeight = 0;
int m_maxTextureCount = 3;
mutable QVector<TextureInfo> m_textures;