From 212ca50d0fe55a658528f190b679142206ac2a01 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Mon, 5 Aug 2024 04:20:52 +0200 Subject: Unload texture if texture loading fails --- src/graphics/Texture.cpp | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/graphics/Texture.cpp b/src/graphics/Texture.cpp index 1bcf3af..0c4b7fc 100644 --- a/src/graphics/Texture.cpp +++ b/src/graphics/Texture.cpp @@ -52,7 +52,13 @@ namespace mgl { load_options.pixel_coordinates, load_options.mipmap }; - return mgl_texture_load_from_file(&texture, filepath, &texture_load_options) == 0; + + if(mgl_texture_load_from_file(&texture, filepath, &texture_load_options) == 0) { + return true; + } else { + clear(); + return false; + } } bool Texture::load_from_image(Image &image, const LoadOptions load_options) { @@ -67,7 +73,13 @@ namespace mgl { load_options.pixel_coordinates, load_options.mipmap }; - return mgl_texture_load_from_image(&texture, image.internal_image(), &texture_load_options) == 0; + + if(mgl_texture_load_from_image(&texture, image.internal_image(), &texture_load_options) == 0) { + return true; + } else { + clear(); + return false; + } } bool Texture::load_from_memory(const unsigned char *data, int width, int height, mgl_image_format format, LoadOptions load_options) { @@ -82,7 +94,13 @@ namespace mgl { load_options.pixel_coordinates, load_options.mipmap }; - return mgl_texture_load_from_memory(&texture, data, width, height, format, &texture_load_options) == 0; + + if(mgl_texture_load_from_memory(&texture, data, width, height, format, &texture_load_options) == 0) { + return true; + } else { + clear(); + return false; + } } void Texture::clear() { -- cgit v1.2.3