aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/scenegraph/util/qsgtexture.cpp
diff options
context:
space:
mode:
authorGunnar Sletta <gunnar.sletta@jollamobile.com>2014-07-03 12:15:46 +0200
committerGunnar Sletta <gunnar.sletta@jollamobile.com>2014-07-04 17:39:45 +0200
commit92658ebb755bda136a7e4fa455b8d116c2dd0c6f (patch)
tree60c346fa4921a8be7448f550ebda033c07e21d49 /src/quick/scenegraph/util/qsgtexture.cpp
parent48dcabdb6f30d5e0c05fc1e56bb4ed4e3a96514c (diff)
Verbose fatal instead of crash when the scene graph state is invalid.
Change-Id: I9a55bcbf9e94084c0cadac561e4707d47f5f8744 Reviewed-by: Robin Burchell <robin+qt@viroteck.net>
Diffstat (limited to 'src/quick/scenegraph/util/qsgtexture.cpp')
-rw-r--r--src/quick/scenegraph/util/qsgtexture.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/quick/scenegraph/util/qsgtexture.cpp b/src/quick/scenegraph/util/qsgtexture.cpp
index 120a3ebf3d..e9e6c14f4e 100644
--- a/src/quick/scenegraph/util/qsgtexture.cpp
+++ b/src/quick/scenegraph/util/qsgtexture.cpp
@@ -48,6 +48,8 @@
#include <QtGui/qguiapplication.h>
#include <QtGui/qpa/qplatformnativeinterface.h>
+#include <private/qsgmaterialshader_p.h>
+
#if defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID) && !defined(__UCLIBC__)
#define CAN_BACKTRACE_EXECINFO
#endif
@@ -271,6 +273,23 @@ static void qt_debug_remove_texture(QSGTexture* texture)
\internal
*/
+#ifndef QT_NO_DEBUG
+Q_GLOBAL_STATIC(QSet<QSGTexture *>, qsg_valid_texture_set)
+Q_GLOBAL_STATIC(QMutex, qsg_valid_texture_mutex)
+
+bool qsg_safeguard_texture(QSGTexture *texture)
+{
+ QMutexLocker locker(qsg_valid_texture_mutex());
+ if (!qsg_valid_texture_set()->contains(texture)) {
+ qWarning() << "Invalid texture accessed:" << (void *) texture;
+ qsg_set_material_failure();
+ glBindTexture(GL_TEXTURE_2D, 0);
+ return false;
+ }
+ return true;
+}
+#endif
+
/*!
Constructs the QSGTexture base class.
*/
@@ -280,6 +299,9 @@ QSGTexture::QSGTexture()
#ifndef QT_NO_DEBUG
if (qsg_leak_check)
qt_debug_add_texture(this);
+
+ QMutexLocker locker(qsg_valid_texture_mutex());
+ qsg_valid_texture_set()->insert(this);
#endif
}
@@ -291,6 +313,9 @@ QSGTexture::~QSGTexture()
#ifndef QT_NO_DEBUG
if (qsg_leak_check)
qt_debug_remove_texture(this);
+
+ QMutexLocker locker(qsg_valid_texture_mutex());
+ qsg_valid_texture_set()->remove(this);
#endif
}