Merge pull request #1772 from Trial97/pixmap_crash
Fix crash with mod icon caching
This commit is contained in:
commit
3d529b0c3e
@ -5,6 +5,7 @@
|
|||||||
#include <QPixmapCache>
|
#include <QPixmapCache>
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
#include <QTime>
|
#include <QTime>
|
||||||
|
#include <limits>
|
||||||
|
|
||||||
#define GET_TYPE() \
|
#define GET_TYPE() \
|
||||||
Qt::ConnectionType type; \
|
Qt::ConnectionType type; \
|
||||||
@ -100,10 +101,14 @@ class PixmapCache final : public QObject {
|
|||||||
*/
|
*/
|
||||||
bool _markCacheMissByEviciton()
|
bool _markCacheMissByEviciton()
|
||||||
{
|
{
|
||||||
|
static constexpr uint maxInt = static_cast<uint>(std::numeric_limits<int>::max());
|
||||||
|
static constexpr uint step = 10240;
|
||||||
|
static constexpr int oneSecond = 1000;
|
||||||
|
|
||||||
auto now = QTime::currentTime();
|
auto now = QTime::currentTime();
|
||||||
if (!m_last_cache_miss_by_eviciton.isNull()) {
|
if (!m_last_cache_miss_by_eviciton.isNull()) {
|
||||||
auto diff = m_last_cache_miss_by_eviciton.msecsTo(now);
|
auto diff = m_last_cache_miss_by_eviciton.msecsTo(now);
|
||||||
if (diff < 1000) { // less than a second ago
|
if (diff < oneSecond) { // less than a second ago
|
||||||
++m_consecutive_fast_evicitons;
|
++m_consecutive_fast_evicitons;
|
||||||
} else {
|
} else {
|
||||||
m_consecutive_fast_evicitons = 0;
|
m_consecutive_fast_evicitons = 0;
|
||||||
@ -111,11 +116,17 @@ class PixmapCache final : public QObject {
|
|||||||
}
|
}
|
||||||
m_last_cache_miss_by_eviciton = now;
|
m_last_cache_miss_by_eviciton = now;
|
||||||
if (m_consecutive_fast_evicitons >= m_consecutive_fast_evicitons_threshold) {
|
if (m_consecutive_fast_evicitons >= m_consecutive_fast_evicitons_threshold) {
|
||||||
// double the cache size
|
// increase the cache size
|
||||||
auto newSize = _cacheLimit() * 2;
|
uint newSize = _cacheLimit() + step;
|
||||||
qDebug() << m_consecutive_fast_evicitons << "pixmap cache misses by eviction happened too fast, doubling cache size to"
|
if (newSize >= maxInt) { // increase it until you overflow :D
|
||||||
<< newSize;
|
newSize = maxInt;
|
||||||
_setCacheLimit(newSize);
|
qDebug() << m_consecutive_fast_evicitons
|
||||||
|
<< tr("pixmap cache misses by eviction happened too fast, doing nothing as the cache size reached it's limit");
|
||||||
|
} else {
|
||||||
|
qDebug() << m_consecutive_fast_evicitons
|
||||||
|
<< tr("pixmap cache misses by eviction happened too fast, increasing cache size to") << static_cast<int>(newSize);
|
||||||
|
}
|
||||||
|
_setCacheLimit(static_cast<int>(newSize));
|
||||||
m_consecutive_fast_evicitons = 0;
|
m_consecutive_fast_evicitons = 0;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user