overlay_controls.cpp: Improve image_info ctor withstandability

This commit is contained in:
Eladash 2022-01-26 08:54:05 +02:00 committed by Ivan
parent 3a1676e558
commit 73ff506b88

View file

@ -27,15 +27,15 @@ namespace rsx
{ {
image_info::image_info(const char* filename) 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; return;
} }
std::vector<u8> bytes; auto bytes = f.to_vector<u8>();
fs::file f(filename);
f.read(bytes, f.size());
data = stbi_load_from_memory(bytes.data(), ::narrow<int>(f.size()), &w, &h, &bpp, STBI_rgb_alpha); data = stbi_load_from_memory(bytes.data(), ::narrow<int>(f.size()), &w, &h, &bpp, STBI_rgb_alpha);
} }
@ -46,9 +46,7 @@ namespace rsx
image_info::~image_info() image_info::~image_info()
{ {
stbi_image_free(data); if (data) stbi_image_free(data);
data = nullptr;
w = h = bpp = 0;
} }
resource_config::resource_config() resource_config::resource_config()