From 1e09be19f57c0dcedc718e5299889fa30d929bc1 Mon Sep 17 00:00:00 2001 From: Megamouse Date: Sun, 14 Mar 2021 18:42:25 +0100 Subject: [PATCH] Qt: Fix PaintedPixmap crash if icon is null --- .../RSX/Overlays/overlay_message_dialog.cpp | 4 +- rpcs3/rpcs3qt/game_list_frame.cpp | 46 ++++++++++--------- 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/rpcs3/Emu/RSX/Overlays/overlay_message_dialog.cpp b/rpcs3/Emu/RSX/Overlays/overlay_message_dialog.cpp index 4a8cf8775d..ec5e2e100b 100644 --- a/rpcs3/Emu/RSX/Overlays/overlay_message_dialog.cpp +++ b/rpcs3/Emu/RSX/Overlays/overlay_message_dialog.cpp @@ -79,12 +79,12 @@ namespace rsx // Set padding in order to keep the aspect ratio if ((background_image->w / static_cast(background_image->h)) > (background_poster.w / static_cast(background_poster.h))) { - const int padding = (background_poster.h - (background_image->h * (background_poster.w / static_cast(background_image->w)))) / 2; + const int padding = (background_poster.h - static_cast(background_image->h * (background_poster.w / static_cast(background_image->w)))) / 2; background_poster.set_padding(0, 0, padding, padding); } else { - const int padding = (background_poster.w - (background_image->w * (background_poster.h / static_cast(background_image->h)))) / 2; + const int padding = (background_poster.w - static_cast(background_image->w * (background_poster.h / static_cast(background_image->h)))) / 2; background_poster.set_padding(padding, padding, 0, 0); } } diff --git a/rpcs3/rpcs3qt/game_list_frame.cpp b/rpcs3/rpcs3qt/game_list_frame.cpp index ce4226858c..7a58157400 100644 --- a/rpcs3/rpcs3qt/game_list_frame.cpp +++ b/rpcs3/rpcs3qt/game_list_frame.cpp @@ -1799,33 +1799,37 @@ 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) { const qreal device_pixel_ratio = devicePixelRatioF(); - - // 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) - { - icon = icon.scaled(320, 176, Qt::KeepAspectRatio); - } - - QSize canvas_size(icon.size()); + QSize canvas_size(320, 176); QPoint target_pos; - // Calculate the centered size and position of the icon on our canvas. - if (icon.width() != 320 || icon.height() != 176) + if (!icon.isNull()) { - ensure(icon.height() > 0); - constexpr double target_ratio = 320.0 / 176.0; // aspect ratio 20:11 - - if ((icon.width() / static_cast(icon.height())) > target_ratio) + // 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) { - canvas_size.setHeight(std::ceil(icon.width() * target_ratio)); - } - else - { - canvas_size.setWidth(std::ceil(icon.height() * target_ratio)); + icon = icon.scaled(320, 176, Qt::KeepAspectRatio); // The resulting icon can be smaller than 320x176 } - target_pos.setX(std::max(0, (canvas_size.width() - icon.width()) / 2.0)); - target_pos.setY(std::max(0, (canvas_size.height() - icon.height()) / 2.0)); + canvas_size = icon.size(); + + if (icon.width() != 320 || icon.height() != 176) + { + // Calculate the centered size and position of the icon on our canvas. + ensure(icon.height() > 0); + constexpr double target_ratio = 320.0 / 176.0; // aspect ratio 20:11 + + if ((icon.width() / static_cast(icon.height())) > target_ratio) + { + canvas_size.setHeight(std::ceil(icon.width() * target_ratio)); + } + else + { + canvas_size.setWidth(std::ceil(icon.height() * target_ratio)); + } + + target_pos.setX(std::max(0, (canvas_size.width() - icon.width()) / 2.0)); + target_pos.setY(std::max(0, (canvas_size.height() - icon.height()) / 2.0)); + } } // Create a canvas large enough to fit our entire scaled icon