From e03363dfd1aeddd085c4c86d9a1964da769d7980 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Mon, 6 Aug 2012 11:51:09 +0200 Subject: Fix potential crash when using text and more than 1 QQuickView MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We need to use a resource guard for the FBO in case there is no current context when the glyph cache is deleted. This reverts commit b3264e2cb6a8fe87754aa1335ab9f8d5e3910c14 which was implemented as a band-aid for this crash. Change-Id: I5b3a09a3998da38836ea851cd0978d3ddadcd2cc Reviewed-by: Samuel Rødal --- .../qsgdefaultdistancefieldglyphcache.cpp | 23 ++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'src/quick/scenegraph/qsgdefaultdistancefieldglyphcache.cpp') diff --git a/src/quick/scenegraph/qsgdefaultdistancefieldglyphcache.cpp b/src/quick/scenegraph/qsgdefaultdistancefieldglyphcache.cpp index 07c17a5791..d889b4028b 100644 --- a/src/quick/scenegraph/qsgdefaultdistancefieldglyphcache.cpp +++ b/src/quick/scenegraph/qsgdefaultdistancefieldglyphcache.cpp @@ -42,19 +42,19 @@ #include "qsgdefaultdistancefieldglyphcache_p.h" #include +#include #include #include #include QT_BEGIN_NAMESPACE - QSGDefaultDistanceFieldGlyphCache::QSGDefaultDistanceFieldGlyphCache(QSGDistanceFieldGlyphCacheManager *man, QOpenGLContext *c, const QRawFont &font) : QSGDistanceFieldGlyphCache(man, c, font) , m_maxTextureSize(0) , m_maxTextureCount(3) - , m_fbo(0) , m_blitProgram(0) + , m_fboGuard(0) { m_blitVertexCoordinateArray[0] = -1.0f; m_blitVertexCoordinateArray[1] = -1.0f; @@ -81,7 +81,10 @@ QSGDefaultDistanceFieldGlyphCache::~QSGDefaultDistanceFieldGlyphCache() { for (int i = 0; i < m_textures.count(); ++i) glDeleteTextures(1, &m_textures[i].texture); - ctx->functions()->glDeleteFramebuffers(1, &m_fbo); + + if (m_fboGuard != 0) + m_fboGuard->free(); + delete m_blitProgram; delete m_areaAllocator; } @@ -215,6 +218,11 @@ void QSGDefaultDistanceFieldGlyphCache::createTexture(TextureInfo *texInfo, int } +static void freeFramebufferFunc(QOpenGLFunctions *funcs, GLuint id) +{ + funcs->glDeleteFramebuffers(1, &id); +} + void QSGDefaultDistanceFieldGlyphCache::resizeTexture(TextureInfo *texInfo, int width, int height) { int oldWidth = texInfo->size.width(); @@ -242,9 +250,12 @@ void QSGDefaultDistanceFieldGlyphCache::resizeTexture(TextureInfo *texInfo, int Q_ASSERT(m_blitProgram); - if (!m_fbo) - ctx->functions()->glGenFramebuffers(1, &m_fbo); - ctx->functions()->glBindFramebuffer(GL_FRAMEBUFFER, m_fbo); + if (!m_fboGuard) { + GLuint fbo; + ctx->functions()->glGenFramebuffers(1, &fbo); + m_fboGuard = new QOpenGLSharedResourceGuard(ctx, fbo, freeFramebufferFunc); + } + ctx->functions()->glBindFramebuffer(GL_FRAMEBUFFER, m_fboGuard->id()); GLuint tmp_texture; glGenTextures(1, &tmp_texture); -- cgit v1.2.3