Commit dcd8f861 authored by Halla Rempt's avatar Halla Rempt
Browse files

Fix crash in the icon cache on exit

Only use the icon cache when Qt >= 5.9; this cache causes crashes
with Qt 5.6 and 5.7 for sure, not tested with 5.9.
parent 3c0d6f95
...@@ -28,21 +28,26 @@ ...@@ -28,21 +28,26 @@
#include <QDebug> #include <QDebug>
#include <KoIcon.h> #include <KoIcon.h>
#if QT_VERSION >= 0x050900
#define CACHE_ICONS
#endif
namespace KisIconUtils namespace KisIconUtils
{ {
#if defined CACHE_ICONS
static QMap<QString, QIcon> s_cache; static QMap<QString, QIcon> s_cache;
#endif
static QMap<qint64, QString> s_icons; static QMap<qint64, QString> s_icons;
QIcon loadIcon(const QString &name) QIcon loadIcon(const QString &name)
{ {
#if defined CACHE_ICONS
QMap<QString, QIcon>::const_iterator cached = s_cache.constFind(name); QMap<QString, QIcon>::const_iterator cached = s_cache.constFind(name);
if (cached != s_cache.constEnd()) { if (cached != s_cache.constEnd()) {
return cached.value(); return cached.value();
} }
#endif
// try load themed icon // try load themed icon
QColor background = qApp->palette().background().color(); QColor background = qApp->palette().background().color();
bool useDarkIcons = background.value() > 100; bool useDarkIcons = background.value() > 100;
...@@ -69,7 +74,9 @@ QIcon loadIcon(const QString &name) ...@@ -69,7 +74,9 @@ QIcon loadIcon(const QString &name)
if (QFile(resname).exists()) { if (QFile(resname).exists()) {
QIcon icon(resname); QIcon icon(resname);
s_icons.insert(icon.cacheKey(), name); s_icons.insert(icon.cacheKey(), name);
#if defined CACHE_ICONS
s_cache.insert(name, icon); s_cache.insert(name, icon);
#endif
return icon; return icon;
} }
} }
...@@ -108,14 +115,18 @@ QIcon loadIcon(const QString &name) ...@@ -108,14 +115,18 @@ QIcon loadIcon(const QString &name)
icon.addFile(p.second, QSize(size, size)); icon.addFile(p.second, QSize(size, size));
} }
s_icons.insert(icon.cacheKey(), name); s_icons.insert(icon.cacheKey(), name);
#if defined CACHE_ICONS
s_cache.insert(name, icon); s_cache.insert(name, icon);
#endif
return icon; return icon;
} }
QIcon icon = QIcon::fromTheme(name); QIcon icon = QIcon::fromTheme(name);
qWarning() << "\tfalling back on QIcon::FromTheme:" << name; qWarning() << "\tfalling back on QIcon::FromTheme:" << name;
s_icons.insert(icon.cacheKey(), name); s_icons.insert(icon.cacheKey(), name);
#if defined CACHE_ICONS
s_cache.insert(name, icon); s_cache.insert(name, icon);
#endif
return icon; return icon;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment