diff options
Diffstat (limited to 'scene/resources/texture.cpp')
-rw-r--r-- | scene/resources/texture.cpp | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/scene/resources/texture.cpp b/scene/resources/texture.cpp index c2e2f85723..b7805b7e38 100644 --- a/scene/resources/texture.cpp +++ b/scene/resources/texture.cpp @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -1333,6 +1333,7 @@ void LargeTexture::set_piece_offset(int p_idx, const Point2 &p_offset) { void LargeTexture::set_piece_texture(int p_idx, const Ref<Texture> &p_texture) { ERR_FAIL_COND(p_texture == this); + ERR_FAIL_COND(p_texture.is_null()); ERR_FAIL_INDEX(p_idx, pieces.size()); pieces.write[p_idx].texture = p_texture; }; @@ -2270,6 +2271,7 @@ void TextureLayered::create(uint32_t p_width, uint32_t p_height, uint32_t p_dept void TextureLayered::set_layer_data(const Ref<Image> &p_image, int p_layer) { ERR_FAIL_COND(!texture.is_valid()); + ERR_FAIL_COND(!p_image.is_valid()); VS::get_singleton()->texture_set_data(texture, p_image, p_layer); } @@ -2281,6 +2283,7 @@ Ref<Image> TextureLayered::get_layer_data(int p_layer) const { void TextureLayered::set_data_partial(const Ref<Image> &p_image, int p_x_ofs, int p_y_ofs, int p_z, int p_mipmap) { ERR_FAIL_COND(!texture.is_valid()); + ERR_FAIL_COND(!p_image.is_valid()); VS::get_singleton()->texture_set_data_partial(texture, p_image, 0, 0, p_image->get_width(), p_image->get_height(), p_x_ofs, p_y_ofs, p_mipmap, p_z); } @@ -2369,16 +2372,20 @@ RES ResourceFormatLoaderTextureLayered::load(const String &p_path, const String if (header[0] == 'G' && header[1] == 'D' && header[2] == '3' && header[3] == 'T') { if (tex3d.is_null()) { + f->close(); memdelete(f); - ERR_FAIL_COND_V(tex3d.is_null(), RES()) + ERR_FAIL_COND_V(tex3d.is_null(), RES()); } } else if (header[0] == 'G' && header[1] == 'D' && header[2] == 'A' && header[3] == 'T') { if (texarr.is_null()) { + f->close(); memdelete(f); - ERR_FAIL_COND_V(texarr.is_null(), RES()) + ERR_FAIL_COND_V(texarr.is_null(), RES()); } } else { + f->close(); + memdelete(f); ERR_FAIL_V_MSG(RES(), "Unrecognized layered texture file format '" + String((const char *)header) + "'."); } @@ -2418,6 +2425,7 @@ RES ResourceFormatLoaderTextureLayered::load(const String &p_path, const String if (r_error) { *r_error = ERR_FILE_CORRUPT; } + f->close(); memdelete(f); ERR_FAIL_V(RES()); } @@ -2453,6 +2461,7 @@ RES ResourceFormatLoaderTextureLayered::load(const String &p_path, const String if (r_error) { *r_error = ERR_FILE_CORRUPT; } + f->close(); memdelete(f); ERR_FAIL_V(RES()); } @@ -2473,8 +2482,9 @@ RES ResourceFormatLoaderTextureLayered::load(const String &p_path, const String if (bytes != total_size) { if (r_error) { *r_error = ERR_FILE_CORRUPT; - memdelete(f); } + f->close(); + memdelete(f); ERR_FAIL_V(RES()); } } |