From 73ff506b882c6a833835665ca2d4f505fd4efa72 Mon Sep 17 00:00:00 2001 From: Eladash Date: Wed, 26 Jan 2022 08:54:05 +0200 Subject: [PATCH] overlay_controls.cpp: Improve image_info ctor withstandability --- rpcs3/Emu/RSX/Overlays/overlay_controls.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/rpcs3/Emu/RSX/Overlays/overlay_controls.cpp b/rpcs3/Emu/RSX/Overlays/overlay_controls.cpp index 53c84545da..2c3b9de694 100644 --- a/rpcs3/Emu/RSX/Overlays/overlay_controls.cpp +++ b/rpcs3/Emu/RSX/Overlays/overlay_controls.cpp @@ -27,15 +27,15 @@ namespace rsx { image_info::image_info(const char* filename) { - if (!fs::is_file(filename)) + fs::file f(filename); + + if (!f) { - rsx_log.error("Image resource file `%s' not found", filename); + rsx_log.error("Image resource file `%s' could not be opened (%s)", filename, fs::g_tls_error); return; } - std::vector bytes; - fs::file f(filename); - f.read(bytes, f.size()); + auto bytes = f.to_vector(); data = stbi_load_from_memory(bytes.data(), ::narrow(f.size()), &w, &h, &bpp, STBI_rgb_alpha); } @@ -46,9 +46,7 @@ namespace rsx image_info::~image_info() { - stbi_image_free(data); - data = nullptr; - w = h = bpp = 0; + if (data) stbi_image_free(data); } resource_config::resource_config()