Do not start timers in QDeclarativePixmapStore teardown
authorLaszlo Agocs <laszlo.p.agocs@nokia.com>
Sun, 29 Jan 2012 15:14:48 +0000 (17:14 +0200)
committerQt by Nokia <qt-info@nokia.com>
Thu, 2 Feb 2012 16:27:12 +0000 (17:27 +0100)
The store instance is a global static and so starting timers
during its destruction is unnecessary, and may cause crashes
if the QAbstractEventDispatcher's statics are already destroyed.
This happens on OS X at least.

Change-Id: I785515c8973b291a7bfc6c5dabe2c19e8393c7ad
Reviewed-by: Martin Jones <martin.jones@nokia.com>

src/quick/util/qdeclarativepixmapcache.cpp

index 15a4637..6460136 100644 (file)
@@ -707,17 +707,20 @@ private:
 
     int m_unreferencedCost;
     int m_timerId;
+    bool m_destroying;
 };
 Q_GLOBAL_STATIC(QDeclarativePixmapStore, pixmapStore);
 
 
 QDeclarativePixmapStore::QDeclarativePixmapStore()
-: m_unreferencedPixmaps(0), m_lastUnreferencedPixmap(0), m_unreferencedCost(0), m_timerId(-1)
+    : m_unreferencedPixmaps(0), m_lastUnreferencedPixmap(0), m_unreferencedCost(0), m_timerId(-1), m_destroying(false)
 {
 }
 
 QDeclarativePixmapStore::~QDeclarativePixmapStore()
 {
+    m_destroying = true;
+
     int leakedPixmaps = 0;
     QList<QDeclarativePixmapData*> cachedData = m_cache.values();
 
@@ -764,7 +767,7 @@ void QDeclarativePixmapStore::unreferencePixmap(QDeclarativePixmapData *data)
 
     shrinkCache(-1); // Shrink the cache incase it has become larger than cache_limit
 
-    if (m_timerId == -1 && m_unreferencedPixmaps) 
+    if (m_timerId == -1 && m_unreferencedPixmaps && !m_destroying)
         m_timerId = startTimer(CACHE_EXPIRE_TIME * 1000);
 }