aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/scenegraph/qsgdefaultdistancefieldglyphcache.cpp
diff options
context:
space:
mode:
authorEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>2012-08-06 11:51:09 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-09-28 16:15:31 +0200
commite03363dfd1aeddd085c4c86d9a1964da769d7980 (patch)
tree9bffd1443a010a418e306cdd06642df7f3f48cbf /src/quick/scenegraph/qsgdefaultdistancefieldglyphcache.cpp
parent5bd0e08063fcacba0c2b63528712968c7d74e7f9 (diff)
Fix potential crash when using text and more than 1 QQuickView
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 <samuel.rodal@digia.com>
Diffstat (limited to 'src/quick/scenegraph/qsgdefaultdistancefieldglyphcache.cpp')
-rw-r--r--src/quick/scenegraph/qsgdefaultdistancefieldglyphcache.cpp23
1 files changed, 17 insertions, 6 deletions
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 <QtGui/private/qdistancefield_p.h>
+#include <QtGui/private/qopenglcontext_p.h>
#include <QtQuick/private/qsgdistancefieldutil_p.h>
#include <qopenglfunctions.h>
#include <qmath.h>
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);