Fix crash in QDeclarativePixmapStore global static dtor
[profile/ivi/qtdeclarative.git] / src / quick / util / qdeclarativepixmapcache.cpp
index 43ce334..1f187a7 100644 (file)
@@ -695,6 +695,8 @@ public:
     void unreferencePixmap(QDeclarativePixmapData *);
     void referencePixmap(QDeclarativePixmapData *);
 
+    void purgeCache();
+
 protected:
     virtual void timerEvent(QTimerEvent *);
 
@@ -760,6 +762,8 @@ void QDeclarativePixmapStore::unreferencePixmap(QDeclarativePixmapData *data)
 
     data->nextUnreferenced = m_unreferencedPixmaps;
     data->prevUnreferencedPtr = &m_unreferencedPixmaps;
+    if (!m_destroying) // the texture factories may have been cleaned up already.
+        m_unreferencedCost += data->cost();
 
     m_unreferencedPixmaps = data;
     if (m_unreferencedPixmaps->nextUnreferenced) {
@@ -770,8 +774,6 @@ void QDeclarativePixmapStore::unreferencePixmap(QDeclarativePixmapData *data)
     if (!m_lastUnreferencedPixmap)
         m_lastUnreferencedPixmap = data;
 
-    m_unreferencedCost += data->cost();
-
     shrinkCache(-1); // Shrink the cache incase it has become larger than cache_limit
 
     if (m_timerId == -1 && m_unreferencedPixmaps && !m_destroying)
@@ -808,8 +810,10 @@ void QDeclarativePixmapStore::shrinkCache(int remove)
         data->prevUnreferencedPtr = 0;
         data->prevUnreferenced = 0;
 
-        remove -= data->cost();
-        m_unreferencedCost -= data->cost();
+        if (!m_destroying) {
+            remove -= data->cost();
+            m_unreferencedCost -= data->cost();
+        }
         data->removeFromCache();
         delete data;
     }
@@ -827,6 +831,16 @@ void QDeclarativePixmapStore::timerEvent(QTimerEvent *)
     }
 }
 
+void QDeclarativePixmapStore::purgeCache()
+{
+    shrinkCache(m_unreferencedCost);
+}
+
+void QDeclarativePixmap::purgeCache()
+{
+    pixmapStore()->purgeCache();
+}
+
 QDeclarativePixmapReply::QDeclarativePixmapReply(QDeclarativePixmapData *d)
 : data(d), engineForReader(0), requestSize(d->requestSize), url(d->url), loading(false), redirectCount(0)
 {