diff options
author | James Beddek <telans@posteo.de> | 2023-06-20 16:59:59 +1200 |
---|---|---|
committer | James Beddek <telans@posteo.de> | 2023-06-20 16:59:59 +1200 |
commit | 75bd626f33a5182facff2ef1f9938f60553c3352 (patch) | |
tree | a3fdf932e54b701d64ce3edc6a792204efff67d7 /launcher/ui/pages/instance | |
parent | f2471f0f68e436d25d27ccc750e6668c07a29070 (diff) | |
download | PrismLauncher-75bd626f33a5182facff2ef1f9938f60553c3352.tar.gz PrismLauncher-75bd626f33a5182facff2ef1f9938f60553c3352.tar.bz2 PrismLauncher-75bd626f33a5182facff2ef1f9938f60553c3352.zip |
Screenshots: do not retry image thumbnailing on null result
This causes the thumbnailing thread pool to spend a lot of time attempting to
retry an image that failed. A null result is common where the image is too large
to be allocated (>128MiB alloc).
The repeated retries continue after page delete, causing hangs if a user
tries to exit the application.
Fixes: #1201
Signed-off-by: James Beddek <telans@posteo.de>
Diffstat (limited to 'launcher/ui/pages/instance')
-rw-r--r-- | launcher/ui/pages/instance/ScreenshotsPage.cpp | 51 |
1 files changed, 22 insertions, 29 deletions
diff --git a/launcher/ui/pages/instance/ScreenshotsPage.cpp b/launcher/ui/pages/instance/ScreenshotsPage.cpp index 9d1f8421..75bb48b2 100644 --- a/launcher/ui/pages/instance/ScreenshotsPage.cpp +++ b/launcher/ui/pages/instance/ScreenshotsPage.cpp @@ -96,37 +96,30 @@ public: return; if ((info.suffix().compare("png", Qt::CaseInsensitive) != 0)) return; - int tries = 5; - while (tries) - { - if (!m_cache->stale(m_path)) - return; - QImage image(m_path); - if (image.isNull()) - { - QThread::msleep(500); - tries--; - continue; - } - QImage small; - if (image.width() > image.height()) - small = image.scaledToWidth(512).scaledToWidth(256, Qt::SmoothTransformation); - else - small = image.scaledToHeight(512).scaledToHeight(256, Qt::SmoothTransformation); - QPoint offset((256 - small.width()) / 2, (256 - small.height()) / 2); - QImage square(QSize(256, 256), QImage::Format_ARGB32); - square.fill(Qt::transparent); - - QPainter painter(&square); - painter.drawImage(offset, small); - painter.end(); - - QIcon icon(QPixmap::fromImage(square)); - m_cache->add(m_path, icon); - m_resultEmitter.emitResultsReady(m_path); + if (!m_cache->stale(m_path)) + return; + QImage image(m_path); + if (image.isNull()) { + m_resultEmitter.emitResultsFailed(m_path); + qDebug() << "Error loading screenshot: " + m_path + ". Perhaps too large?"; return; } - m_resultEmitter.emitResultsFailed(m_path); + QImage small; + if (image.width() > image.height()) + small = image.scaledToWidth(512).scaledToWidth(256, Qt::SmoothTransformation); + else + small = image.scaledToHeight(512).scaledToHeight(256, Qt::SmoothTransformation); + QPoint offset((256 - small.width()) / 2, (256 - small.height()) / 2); + QImage square(QSize(256, 256), QImage::Format_ARGB32); + square.fill(Qt::transparent); + + QPainter painter(&square); + painter.drawImage(offset, small); + painter.end(); + + QIcon icon(QPixmap::fromImage(square)); + m_cache->add(m_path, icon); + m_resultEmitter.emitResultsReady(m_path); } QString m_path; SharedIconCachePtr m_cache; |