From 92b36d47066117d6e9fbc6c6506ba89db2b2a712 Mon Sep 17 00:00:00 2001 From: Haoyu Qiu Date: Thu, 16 Jan 2020 21:46:07 +0800 Subject: Adds NULL check before using image loader --- editor/import/editor_scene_importer_gltf.cpp | 4 ++++ modules/assimp/import_utils.h | 2 ++ 2 files changed, 6 insertions(+) diff --git a/editor/import/editor_scene_importer_gltf.cpp b/editor/import/editor_scene_importer_gltf.cpp index 7de6db7add..a418915830 100644 --- a/editor/import/editor_scene_importer_gltf.cpp +++ b/editor/import/editor_scene_importer_gltf.cpp @@ -1302,6 +1302,8 @@ Error EditorSceneImporterGLTF::_parse_images(GLTFState &state, const String &p_b if (mimetype.findn("png") != -1) { //is a png + ERR_FAIL_COND_V(Image::_png_mem_loader_func == NULL, ERR_UNAVAILABLE); + const Ref img = Image::_png_mem_loader_func(data_ptr, data_size); ERR_FAIL_COND_V(img.is_null(), ERR_FILE_CORRUPT); @@ -1316,6 +1318,8 @@ Error EditorSceneImporterGLTF::_parse_images(GLTFState &state, const String &p_b if (mimetype.findn("jpeg") != -1) { //is a jpg + ERR_FAIL_COND_V(Image::_jpg_mem_loader_func == NULL, ERR_UNAVAILABLE); + const Ref img = Image::_jpg_mem_loader_func(data_ptr, data_size); ERR_FAIL_COND_V(img.is_null(), ERR_FILE_CORRUPT); diff --git a/modules/assimp/import_utils.h b/modules/assimp/import_utils.h index f4505249db..c522b01727 100644 --- a/modules/assimp/import_utils.h +++ b/modules/assimp/import_utils.h @@ -355,11 +355,13 @@ public: print_verbose("Open Asset Import: Loading embedded texture " + filename); if (tex->mHeight == 0) { if (tex->CheckFormat("png")) { + ERR_FAIL_COND_V(Image::_png_mem_loader_func == NULL, Ref()); Ref img = Image::_png_mem_loader_func((uint8_t *)tex->pcData, tex->mWidth); ERR_FAIL_COND_V(img.is_null(), Ref()); state.path_to_image_cache.insert(p_path, img); return img; } else if (tex->CheckFormat("jpg")) { + ERR_FAIL_COND_V(Image::_jpg_mem_loader_func == NULL, Ref()); Ref img = Image::_jpg_mem_loader_func((uint8_t *)tex->pcData, tex->mWidth); ERR_FAIL_COND_V(img.is_null(), Ref()); state.path_to_image_cache.insert(p_path, img); -- cgit v1.2.3