summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2017-12-05 14:31:43 +0100
committerPasi Keränen <pasi.keranen@qt.io>2017-12-30 07:33:40 +0000
commit29e490679e2e3610c62750eb96d9c4b81205cf96 (patch)
tree2ac457c8e24ad04cd32386cc8a32f87a276dedb1 /src
parent3ffb0d49d3e6b420c8c0952d2b780c95baf3cb0b (diff)
Fix crash on application exit
The destruction order of global statics is undefined. If the factory map got destroyed before the map deleter, we would not only leak memory, but also access a deleted object, which is undefined behaviour and did lead to crashes for me. Change-Id: I27c664751b1acdaa08cf35989e09db3e06c6b3c1 Reviewed-by: Pasi Keränen <pasi.keranen@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/imports/qtcanvas3d/teximage3d.cpp21
1 files changed, 13 insertions, 8 deletions
diff --git a/src/imports/qtcanvas3d/teximage3d.cpp b/src/imports/qtcanvas3d/teximage3d.cpp
index d3e1e07..9814e6b 100644
--- a/src/imports/qtcanvas3d/teximage3d.cpp
+++ b/src/imports/qtcanvas3d/teximage3d.cpp
@@ -47,18 +47,23 @@ QT_BEGIN_NAMESPACE
QT_CANVAS3D_BEGIN_NAMESPACE
-static QMap<QQmlEngine *,CanvasTextureImageFactory *>m_qmlEngineToImageFactoryMap;
-static ulong m_texId = 0;
-
-class StaticFactoryMapDeleter
+class EngineToImageFactoryMap : public QMap<QQmlEngine *, CanvasTextureImageFactory *>
{
+ bool isDeleting = false;
public:
- StaticFactoryMapDeleter() {}
- ~StaticFactoryMapDeleter() {
- qDeleteAll(m_qmlEngineToImageFactoryMap);
+ ~EngineToImageFactoryMap() {
+ isDeleting = true;
+ qDeleteAll(*this);
+ }
+ void remove(QQmlEngine *e) {
+ if (isDeleting)
+ return;
+ QMap<QQmlEngine *, CanvasTextureImageFactory *>::remove(e);
}
};
-static StaticFactoryMapDeleter staticFactoryMapDeleter;
+
+static EngineToImageFactoryMap m_qmlEngineToImageFactoryMap;
+static ulong m_texId = 0;
CanvasTextureImageFactory::CanvasTextureImageFactory(QQmlEngine *engine, QObject *parent) :
QObject(parent)