mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-20 12:35:43 +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 "blackconfig/buildconfig.h"
|
||||||
#include "blackmisc/fileutils.h"
|
#include "blackmisc/fileutils.h"
|
||||||
#include "blackmisc/icons.h"
|
#include "blackmisc/icons.h"
|
||||||
|
#include "blackmisc/threadutils.h"
|
||||||
|
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
#include <QImage>
|
#include <QImage>
|
||||||
@@ -1143,20 +1144,16 @@ namespace BlackMisc
|
|||||||
|
|
||||||
const QPixmap &CIcons::pixmapByResourceFileName(const QString &fileName)
|
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(!fileName.isEmpty(), Q_FUNC_INFO, "missing filename");
|
||||||
|
Q_ASSERT_X(CThreadUtils::isCurrentThreadApplicationThread(), Q_FUNC_INFO, "not thread safe");
|
||||||
|
|
||||||
if (!getResourceFileCache().contains(fileName))
|
if (!getResourceFileCache().contains(fileName))
|
||||||
{
|
{
|
||||||
const QString path = CFileUtils::appendFilePaths(CBuildConfig::getImagesDir(), fileName);
|
const QString path = CFileUtils::appendFilePaths(CBuildConfig::getImagesDir(), fileName);
|
||||||
QPixmap pm;
|
QPixmap pm;
|
||||||
const bool s = pm.load(path);
|
const bool s = pm.load(path);
|
||||||
if (s)
|
getResourceFileCache().insert(fileName, s ? pm : CIcons::empty());
|
||||||
{
|
|
||||||
getResourceFileCache().insert(fileName, pm);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
getResourceFileCache().insert(fileName, CIcons::empty());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return getResourceFileCache()[fileName];
|
return getResourceFileCache()[fileName];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -703,7 +703,7 @@ namespace BlackMisc
|
|||||||
static QPixmap rotate(int rotateDegrees, const QPixmap &original);
|
static QPixmap rotate(int rotateDegrees, const QPixmap &original);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//! File cache for the loaded
|
//! File cache for the loaded files
|
||||||
static QMap<QString, QPixmap> &getResourceFileCache();
|
static QMap<QString, QPixmap> &getResourceFileCache();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user