Qt: Fix PaintedPixmap crash if icon is null

This commit is contained in:
Megamouse 2021-03-14 18:42:25 +01:00
parent c1de0bc28c
commit 1e09be19f5
2 changed files with 27 additions and 23 deletions

View File

@ -79,12 +79,12 @@ namespace rsx
// Set padding in order to keep the aspect ratio // Set padding in order to keep the aspect ratio
if ((background_image->w / static_cast<double>(background_image->h)) > (background_poster.w / static_cast<double>(background_poster.h))) if ((background_image->w / static_cast<double>(background_image->h)) > (background_poster.w / static_cast<double>(background_poster.h)))
{ {
const int padding = (background_poster.h - (background_image->h * (background_poster.w / static_cast<double>(background_image->w)))) / 2; const int padding = (background_poster.h - static_cast<int>(background_image->h * (background_poster.w / static_cast<double>(background_image->w)))) / 2;
background_poster.set_padding(0, 0, padding, padding); background_poster.set_padding(0, 0, padding, padding);
} }
else else
{ {
const int padding = (background_poster.w - (background_image->w * (background_poster.h / static_cast<double>(background_image->h)))) / 2; const int padding = (background_poster.w - static_cast<int>(background_image->w * (background_poster.h / static_cast<double>(background_image->h)))) / 2;
background_poster.set_padding(padding, padding, 0, 0); background_poster.set_padding(padding, padding, 0, 0);
} }
} }

View File

@ -1799,19 +1799,22 @@ void game_list_frame::BatchRemoveShaderCaches()
QPixmap game_list_frame::PaintedPixmap(QPixmap icon, bool paint_config_icon, bool paint_pad_config_icon, const QColor& compatibility_color) QPixmap game_list_frame::PaintedPixmap(QPixmap icon, bool paint_config_icon, bool paint_pad_config_icon, const QColor& compatibility_color)
{ {
const qreal device_pixel_ratio = devicePixelRatioF(); const qreal device_pixel_ratio = devicePixelRatioF();
QSize canvas_size(320, 176);
QPoint target_pos;
if (!icon.isNull())
{
// Let's upscale the original icon to at least fit into the outer rect of the size of PS3's ICON0.PNG // Let's upscale the original icon to at least fit into the outer rect of the size of PS3's ICON0.PNG
if (icon.width() < 320 || icon.height() < 176) if (icon.width() < 320 || icon.height() < 176)
{ {
icon = icon.scaled(320, 176, Qt::KeepAspectRatio); icon = icon.scaled(320, 176, Qt::KeepAspectRatio); // The resulting icon can be smaller than 320x176
} }
QSize canvas_size(icon.size()); canvas_size = icon.size();
QPoint target_pos;
// Calculate the centered size and position of the icon on our canvas.
if (icon.width() != 320 || icon.height() != 176) if (icon.width() != 320 || icon.height() != 176)
{ {
// Calculate the centered size and position of the icon on our canvas.
ensure(icon.height() > 0); ensure(icon.height() > 0);
constexpr double target_ratio = 320.0 / 176.0; // aspect ratio 20:11 constexpr double target_ratio = 320.0 / 176.0; // aspect ratio 20:11
@ -1827,6 +1830,7 @@ QPixmap game_list_frame::PaintedPixmap(QPixmap icon, bool paint_config_icon, boo
target_pos.setX(std::max<int>(0, (canvas_size.width() - icon.width()) / 2.0)); target_pos.setX(std::max<int>(0, (canvas_size.width() - icon.width()) / 2.0));
target_pos.setY(std::max<int>(0, (canvas_size.height() - icon.height()) / 2.0)); target_pos.setY(std::max<int>(0, (canvas_size.height() - icon.height()) / 2.0));
} }
}
// Create a canvas large enough to fit our entire scaled icon // Create a canvas large enough to fit our entire scaled icon
QPixmap canvas(canvas_size * device_pixel_ratio); QPixmap canvas(canvas_size * device_pixel_ratio);