From c0cfc1ed958fe27a801217707f0adca84ec4400e Mon Sep 17 00:00:00 2001 From: Keiji Yoshimi Date: Tue, 28 Aug 2018 21:13:03 +0900 Subject: [PATCH] handling stbi_write_xxx_to_func return code --- tiny_gltf.h | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/tiny_gltf.h b/tiny_gltf.h index e253fce..fc5f189 100644 --- a/tiny_gltf.h +++ b/tiny_gltf.h @@ -1385,18 +1385,24 @@ bool WriteImageData(const std::string *basepath, const std::string *filename, std::vector data; if (ext == "png") { - stbi_write_png_to_func(WriteToMemory_stbi, &data, image->width, + if (!stbi_write_png_to_func(WriteToMemory_stbi, &data, image->width, image->height, image->component, &image->image[0], - 0); + 0)) { + return false; + } header = "data:image/png;base64,"; } else if (ext == "jpg") { - stbi_write_jpg_to_func(WriteToMemory_stbi, &data, image->width, + if (!stbi_write_jpg_to_func(WriteToMemory_stbi, &data, image->width, image->height, image->component, &image->image[0], - 100); + 100)) { + return false; + } header = "data:image/jpeg;base64,"; } else if (ext == "bmp") { - stbi_write_bmp_to_func(WriteToMemory_stbi, &data, image->width, - image->height, image->component, &image->image[0]); + if (!stbi_write_bmp_to_func(WriteToMemory_stbi, &data, image->width, + image->height, image->component, &image->image[0])) { + return false; + } header = "data:image/bmp;base64,"; } else if (!embedImages) { // Error: can't output requested format to file @@ -1421,6 +1427,7 @@ bool WriteImageData(const std::string *basepath, const std::string *filename, if (!fs->WriteWholeFile(&writeError, imagefilepath, data, fs->user_data)) { // Could not write image file to disc; Throw error ? + return false; } } else { // Throw error?