mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 23:05:36 +08:00
Check thread for icon cache (assert)
This commit is contained in:
committed by
Mathew Sutcliffe
parent
9ad721b77a
commit
709b9a3dd9
@@ -12,6 +12,7 @@
|
||||
#include "blackconfig/buildconfig.h"
|
||||
#include "blackmisc/fileutils.h"
|
||||
#include "blackmisc/icons.h"
|
||||
#include "blackmisc/threadutils.h"
|
||||
|
||||
#include <QIcon>
|
||||
#include <QImage>
|
||||
@@ -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];
|
||||
}
|
||||
|
||||
@@ -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<QString, QPixmap> &getResourceFileCache();
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user