aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2024-08-05 04:20:52 +0200
committerdec05eba <dec05eba@protonmail.com>2024-08-05 04:20:52 +0200
commit212ca50d0fe55a658528f190b679142206ac2a01 (patch)
tree82af507df220e06cb6d391928bf946a14c68ec6b /src
parentd0e8c89aecdbf6c26883863f310a0a8ffaa29403 (diff)
Unload texture if texture loading fails
Diffstat (limited to 'src')
-rw-r--r--src/graphics/Texture.cpp24
1 files 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() {