From 9a9b891db491953c5b2d922aacb25aba0dce6771 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Trond=20Kjern=C3=A5sen?= Date: Wed, 27 Oct 2010 11:19:20 +0200 Subject: Fixes unstability caused by a dangling pointer in GL text rendering Reviewed-by: eskil --- src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp | 3 ++- src/opengl/gl2paintengineex/qtextureglyphcache_gl.cpp | 12 ++++++------ src/opengl/gl2paintengineex/qtextureglyphcache_gl_p.h | 4 +++- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp index 025731d..fba3b20 100644 --- a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp +++ b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp @@ -1477,9 +1477,10 @@ void QGL2PaintEngineExPrivate::drawCachedGlyphs(QFontEngineGlyphCache::Type glyp void *cacheKey = const_cast(QGLContextPrivate::contextGroup(ctx)->context()); QGLTextureGlyphCache *cache = (QGLTextureGlyphCache *) staticTextItem->fontEngine->glyphCache(cacheKey, glyphType, QTransform()); - if (!cache || cache->cacheType() != glyphType) { + if (!cache || cache->cacheType() != glyphType || cache->context() == 0) { cache = new QGLTextureGlyphCache(ctx, glyphType, QTransform()); staticTextItem->fontEngine->setGlyphCache(cacheKey, cache); + cache->insert(ctx, cache); } bool recreateVertexArrays = false; diff --git a/src/opengl/gl2paintengineex/qtextureglyphcache_gl.cpp b/src/opengl/gl2paintengineex/qtextureglyphcache_gl.cpp index b8576cb..f185f9a 100644 --- a/src/opengl/gl2paintengineex/qtextureglyphcache_gl.cpp +++ b/src/opengl/gl2paintengineex/qtextureglyphcache_gl.cpp @@ -54,11 +54,11 @@ extern Q_GUI_EXPORT bool qt_cleartype_enabled; #endif QGLTextureGlyphCache::QGLTextureGlyphCache(const QGLContext *context, QFontEngineGlyphCache::Type type, const QTransform &matrix) - : QImageTextureGlyphCache(type, matrix) + : QImageTextureGlyphCache(type, matrix), QGLContextGroupResourceBase() , ctx(context) , pex(0) - , m_filterMode(Nearest) , m_blitProgram(0) + , m_filterMode(Nearest) { #ifdef QT_GL_TEXTURE_GLYPH_CACHE_DEBUG qDebug(" -> QGLTextureGlyphCache() %p for context %p.", this, ctx); @@ -208,8 +208,8 @@ void QGLTextureGlyphCache::resizeTextureData(int width, int height) { QString source; - source.append(qglslMainWithTexCoordsVertexShader); - source.append(qglslUntransformedPositionVertexShader); + source.append(QLatin1String(qglslMainWithTexCoordsVertexShader)); + source.append(QLatin1String(qglslUntransformedPositionVertexShader)); QGLShader *vertexShader = new QGLShader(QGLShader::Vertex, m_blitProgram); vertexShader->compileSourceCode(source); @@ -219,8 +219,8 @@ void QGLTextureGlyphCache::resizeTextureData(int width, int height) { QString source; - source.append(qglslMainFragmentShader); - source.append(qglslImageSrcFragmentShader); + source.append(QLatin1String(qglslMainFragmentShader)); + source.append(QLatin1String(qglslImageSrcFragmentShader)); QGLShader *fragmentShader = new QGLShader(QGLShader::Fragment, m_blitProgram); fragmentShader->compileSourceCode(source); diff --git a/src/opengl/gl2paintengineex/qtextureglyphcache_gl_p.h b/src/opengl/gl2paintengineex/qtextureglyphcache_gl_p.h index f75cf68..572da82 100644 --- a/src/opengl/gl2paintengineex/qtextureglyphcache_gl_p.h +++ b/src/opengl/gl2paintengineex/qtextureglyphcache_gl_p.h @@ -98,7 +98,7 @@ struct QGLGlyphTexture int m_height; }; -class Q_OPENGL_EXPORT QGLTextureGlyphCache : public QImageTextureGlyphCache +class Q_OPENGL_EXPORT QGLTextureGlyphCache : public QImageTextureGlyphCache, public QGLContextGroupResourceBase { public: QGLTextureGlyphCache(const QGLContext *context, QFontEngineGlyphCache::Type type, const QTransform &matrix); @@ -140,6 +140,8 @@ public: FilterMode filterMode() const { return m_filterMode; } void setFilterMode(FilterMode m) { m_filterMode = m; } + void freeResource(void *) { ctx = 0; } + private: QGLContextGroupResource m_textureResource; -- cgit v0.12