From 709b9a3dd9da84f466a5e09106419f6a7ba256d7 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Sat, 1 Jul 2017 17:15:43 +0200 Subject: [PATCH] Check thread for icon cache (assert) --- src/blackmisc/icons.cpp | 13 +++++-------- src/blackmisc/icons.h | 2 +- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/blackmisc/icons.cpp b/src/blackmisc/icons.cpp index 5fb62a62b..c2c66d6a5 100644 --- a/src/blackmisc/icons.cpp +++ b/src/blackmisc/icons.cpp @@ -12,6 +12,7 @@ #include "blackconfig/buildconfig.h" #include "blackmisc/fileutils.h" #include "blackmisc/icons.h" +#include "blackmisc/threadutils.h" #include #include @@ -1143,20 +1144,16 @@ namespace BlackMisc const QPixmap &CIcons::pixmapByResourceFileName(const QString &fileName) { + //! \fixme KB 20170701 noticed the "cache" is not threadsafe. However, there has never be an issue so far. Added thread assert. Q_ASSERT_X(!fileName.isEmpty(), Q_FUNC_INFO, "missing filename"); + Q_ASSERT_X(CThreadUtils::isCurrentThreadApplicationThread(), Q_FUNC_INFO, "not thread safe"); + if (!getResourceFileCache().contains(fileName)) { const QString path = CFileUtils::appendFilePaths(CBuildConfig::getImagesDir(), fileName); QPixmap pm; const bool s = pm.load(path); - if (s) - { - getResourceFileCache().insert(fileName, pm); - } - else - { - getResourceFileCache().insert(fileName, CIcons::empty()); - } + getResourceFileCache().insert(fileName, s ? pm : CIcons::empty()); } return getResourceFileCache()[fileName]; } diff --git a/src/blackmisc/icons.h b/src/blackmisc/icons.h index 49223154e..afabb4089 100644 --- a/src/blackmisc/icons.h +++ b/src/blackmisc/icons.h @@ -703,7 +703,7 @@ namespace BlackMisc static QPixmap rotate(int rotateDegrees, const QPixmap &original); private: - //! File cache for the loaded + //! File cache for the loaded files static QMap &getResourceFileCache(); }; }