Adds NULL check before using image loader

This commit is contained in:
Haoyu Qiu 2020-01-16 21:46:07 +08:00
parent bc34794840
commit 92b36d4706
2 changed files with 6 additions and 0 deletions

View File

@ -1302,6 +1302,8 @@ Error EditorSceneImporterGLTF::_parse_images(GLTFState &state, const String &p_b
if (mimetype.findn("png") != -1) { if (mimetype.findn("png") != -1) {
//is a png //is a png
ERR_FAIL_COND_V(Image::_png_mem_loader_func == NULL, ERR_UNAVAILABLE);
const Ref<Image> img = Image::_png_mem_loader_func(data_ptr, data_size); const Ref<Image> img = Image::_png_mem_loader_func(data_ptr, data_size);
ERR_FAIL_COND_V(img.is_null(), ERR_FILE_CORRUPT); 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) { if (mimetype.findn("jpeg") != -1) {
//is a jpg //is a jpg
ERR_FAIL_COND_V(Image::_jpg_mem_loader_func == NULL, ERR_UNAVAILABLE);
const Ref<Image> img = Image::_jpg_mem_loader_func(data_ptr, data_size); const Ref<Image> img = Image::_jpg_mem_loader_func(data_ptr, data_size);
ERR_FAIL_COND_V(img.is_null(), ERR_FILE_CORRUPT); ERR_FAIL_COND_V(img.is_null(), ERR_FILE_CORRUPT);

View File

@ -355,11 +355,13 @@ public:
print_verbose("Open Asset Import: Loading embedded texture " + filename); print_verbose("Open Asset Import: Loading embedded texture " + filename);
if (tex->mHeight == 0) { if (tex->mHeight == 0) {
if (tex->CheckFormat("png")) { if (tex->CheckFormat("png")) {
ERR_FAIL_COND_V(Image::_png_mem_loader_func == NULL, Ref<Image>());
Ref<Image> img = Image::_png_mem_loader_func((uint8_t *)tex->pcData, tex->mWidth); Ref<Image> img = Image::_png_mem_loader_func((uint8_t *)tex->pcData, tex->mWidth);
ERR_FAIL_COND_V(img.is_null(), Ref<Image>()); ERR_FAIL_COND_V(img.is_null(), Ref<Image>());
state.path_to_image_cache.insert(p_path, img); state.path_to_image_cache.insert(p_path, img);
return img; return img;
} else if (tex->CheckFormat("jpg")) { } else if (tex->CheckFormat("jpg")) {
ERR_FAIL_COND_V(Image::_jpg_mem_loader_func == NULL, Ref<Image>());
Ref<Image> img = Image::_jpg_mem_loader_func((uint8_t *)tex->pcData, tex->mWidth); Ref<Image> img = Image::_jpg_mem_loader_func((uint8_t *)tex->pcData, tex->mWidth);
ERR_FAIL_COND_V(img.is_null(), Ref<Image>()); ERR_FAIL_COND_V(img.is_null(), Ref<Image>());
state.path_to_image_cache.insert(p_path, img); state.path_to_image_cache.insert(p_path, img);