From 1a53c04c62d6fb31fba8d746eeb8c737ad50f6a7 Mon Sep 17 00:00:00 2001 From: nikitalita <69168929+nikitalita@users.noreply.github.com> Date: Tue, 5 Nov 2024 21:29:54 -0600 Subject: [PATCH] fix bugs in converters --- compat/oggstr_loader_compat.cpp | 2 ++ compat/texture_loader_compat.cpp | 36 +++++++++++++++----------------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/compat/oggstr_loader_compat.cpp b/compat/oggstr_loader_compat.cpp index 9592daf1..c0733051 100644 --- a/compat/oggstr_loader_compat.cpp +++ b/compat/oggstr_loader_compat.cpp @@ -1,4 +1,5 @@ #include "oggstr_loader_compat.h" +#include "core/error/error_macros.h" #include "modules/vorbis/resource_importer_ogg_vorbis.h" Ref OggStreamConverterCompat::convert(const Ref &res, ResourceInfo::LoadType p_type, int ver_major, Error *r_error) { @@ -7,6 +8,7 @@ Ref OggStreamConverterCompat::convert(const Ref &res, bool loop = res->get("loop"); double loop_offset = res->get("loop_offset"); Ref sample = ResourceImporterOggVorbis::load_from_buffer(data); + ERR_FAIL_COND_V_MSG(sample.is_null(), res, "Failed to load Ogg Vorbis stream from buffer."); if (!name.is_empty()) { sample->set_name(name); } diff --git a/compat/texture_loader_compat.cpp b/compat/texture_loader_compat.cpp index 0f784450..e3d6af82 100644 --- a/compat/texture_loader_compat.cpp +++ b/compat/texture_loader_compat.cpp @@ -726,6 +726,7 @@ Ref ResourceConverterTexture2D::convert(const Ref &re } else if (p_type == ResourceInfo::REAL_LOAD) { texture = ResourceCompatLoader::real_load(load_path, type, ResourceFormatLoader::CACHE_MODE_IGNORE, r_error); } + ERR_FAIL_COND_V_MSG(texture.is_null(), res, "Failed to load texture " + load_path); if (compat_dict.size() > 0) { texture->set_meta("compat", compat_dict); } @@ -1040,28 +1041,25 @@ Ref ImageTextureConverterCompat::convert(const Ref &r } return image; }; - if (type == "ImageTexture") { - name = get_resource_name(res, ver_major); - image = convert_image(res->get("image")); - ERR_FAIL_COND_V_MSG(image.is_null(), res, "Cannot load resource '" + name + "'."); + ERR_FAIL_COND_V_MSG(type != "ImageTexture", res, "Unsupported type: " + type); + name = get_resource_name(res, ver_major); + image = convert_image(res->get("image")); + ERR_FAIL_COND_V_MSG(image.is_null(), res, "Cannot load image from ImageTexture resource '" + name + "'."); - size = res->get("size"); - flags = res->get("flags"); - bool mipmaps = flags & 1 || image->has_mipmaps(); + size = res->get("size"); + flags = res->get("flags"); + bool mipmaps = flags & 1 || image->has_mipmaps(); - image->set_name(name); - tw = image->get_width(); - th = image->get_height(); - if (size.width && tw != size.width) { - tw_custom = size.width; - } - if (size.height && th != size.height) { - th_custom = size.height; - } - texture = TextureLoaderCompat::create_image_texture(res->get_path(), p_type, tw, th, tw_custom, th_custom, mipmaps, image); - } else { - ERR_FAIL_V_MSG(res, "Unsupported type: " + type); + image->set_name(name); + tw = image->get_width(); + th = image->get_height(); + if (size.width && tw != size.width) { + tw_custom = size.width; + } + if (size.height && th != size.height) { + th_custom = size.height; } + texture = TextureLoaderCompat::create_image_texture(res->get_path(), p_type, tw, th, tw_custom, th_custom, mipmaps, image); if (compat_dict.size() > 0) { texture->set_meta("compat", compat_dict); }