From 24c6e4a81db2c54136abaf4076cc55b11fec6aaf Mon Sep 17 00:00:00 2001 From: Fabio Bas Date: Fri, 16 Jan 2015 17:11:38 +0100 Subject: [PATCH] Limit pixmap cache size to 2047MB; fix #555 also, fix any invalid values loaded from config --- cockatrice/src/dlg_settings.cpp | 5 +++-- cockatrice/src/settingscache.cpp | 4 ++++ cockatrice/src/settingscache.h | 2 ++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/cockatrice/src/dlg_settings.cpp b/cockatrice/src/dlg_settings.cpp index 95479b84..fab52dde 100644 --- a/cockatrice/src/dlg_settings.cpp +++ b/cockatrice/src/dlg_settings.cpp @@ -52,8 +52,9 @@ GeneralSettingsPage::GeneralSettingsPage() pixmapCacheLabel = new QLabel; pixmapCacheEdit = new QSpinBox; - pixmapCacheEdit->setMinimum(64); - pixmapCacheEdit->setMaximum(8192); + pixmapCacheEdit->setMinimum(PIXMAPCACHE_SIZE_MIN); + // 2047 is the max value to avoid overflowing of QPixmapCache::setCacheLimit(int size) + pixmapCacheEdit->setMaximum(PIXMAPCACHE_SIZE_MAX); pixmapCacheEdit->setSingleStep(64); pixmapCacheEdit->setValue(settingsCache->getPixmapCacheSize()); pixmapCacheEdit->setSuffix(" MB"); diff --git a/cockatrice/src/settingscache.cpp b/cockatrice/src/settingscache.cpp index c96e4da0..2bd5361b 100644 --- a/cockatrice/src/settingscache.cpp +++ b/cockatrice/src/settingscache.cpp @@ -24,6 +24,10 @@ SettingsCache::SettingsCache() picDownload = settings->value("personal/picturedownload", true).toBool(); picDownloadHq = settings->value("personal/picturedownloadhq", false).toBool(); pixmapCacheSize = settings->value("personal/pixmapCacheSize", PIXMAPCACHE_SIZE_DEFAULT).toInt(); + //sanity check + if(pixmapCacheSize < PIXMAPCACHE_SIZE_MIN || pixmapCacheSize > PIXMAPCACHE_SIZE_MAX) + pixmapCacheSize = PIXMAPCACHE_SIZE_DEFAULT; + picUrl = settings->value("personal/picUrl", PIC_URL_DEFAULT).toString(); picUrlHq = settings->value("personal/picUrlHq", PIC_URL_HQ_DEFAULT).toString(); picUrlFallback = settings->value("personal/picUrlFallback", PIC_URL_FALLBACK).toString(); diff --git a/cockatrice/src/settingscache.h b/cockatrice/src/settingscache.h index 839aca0f..31a99304 100644 --- a/cockatrice/src/settingscache.h +++ b/cockatrice/src/settingscache.h @@ -9,6 +9,8 @@ #define PIC_URL_HQ_FALLBACK "http://mtgimage.com/set/!setcode!/!name!.jpg" // size should be a multiple of 64 #define PIXMAPCACHE_SIZE_DEFAULT 256 +#define PIXMAPCACHE_SIZE_MIN 64 +#define PIXMAPCACHE_SIZE_MAX 2047 class QSettings;