From 242ceb1869e09b5c1773c7353e38ccab31602ad9 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Tue, 28 Jun 2016 12:35:11 -0300 Subject: [PATCH] Remove error when getting dependencies from tscn files in some cases, closes #3897 (cherry picked from commit 519fce94e97888d37efc11b44e6cc6cb01b51a3a) --- scene/resources/scene_format_text.cpp | 53 +++++++++++++++++---------- scene/resources/scene_format_text.h | 2 +- 2 files changed, 34 insertions(+), 21 deletions(-) diff --git a/scene/resources/scene_format_text.cpp b/scene/resources/scene_format_text.cpp index 08d12b1465d..25ca41392b9 100644 --- a/scene/resources/scene_format_text.cpp +++ b/scene/resources/scene_format_text.cpp @@ -39,12 +39,17 @@ Error ResourceInteractiveLoaderText::_parse_sub_resource(VariantParser::Stream* String path = local_path+"::"+itos(index); - if (!ResourceCache::has(path)) { - r_err_str="Can't load cached sub-resource: "+path; - return ERR_PARSE_ERROR; - } + if (!ignore_resource_parsing) { - r_res=RES(ResourceCache::get(path)); + if (!ResourceCache::has(path)) { + r_err_str="Can't load cached sub-resource: "+path; + return ERR_PARSE_ERROR; + } + + r_res=RES(ResourceCache::get(path)); + } else { + r_res=RES(); + } VariantParser::get_token(p_stream,token,line,r_err_str); if (token.type!=VariantParser::TK_PARENTHESIS_CLOSE) { @@ -67,25 +72,29 @@ Error ResourceInteractiveLoaderText::_parse_ext_resource(VariantParser::Stream* int id = token.value; + if (!ignore_resource_parsing) { - if (!ext_resources.has(id)) { - r_err_str="Can't load cached ext-resource #"+itos(id); - return ERR_PARSE_ERROR; - } + if (!ext_resources.has(id)) { + r_err_str="Can't load cached ext-resource #"+itos(id); + return ERR_PARSE_ERROR; + } - String path = ext_resources[id].path; - String type = ext_resources[id].type; + String path = ext_resources[id].path; + String type = ext_resources[id].type; - if (path.find("://")==-1 && path.is_rel_path()) { - // path is relative to file being loaded, so convert to a resource path - path=Globals::get_singleton()->localize_path(res_path.get_base_dir().plus_file(path)); + if (path.find("://")==-1 && path.is_rel_path()) { + // path is relative to file being loaded, so convert to a resource path + path=Globals::get_singleton()->localize_path(res_path.get_base_dir().plus_file(path)); - } + } - r_res=ResourceLoader::load(path,type); + r_res=ResourceLoader::load(path,type); - if (r_res.is_null()) { - WARN_PRINT(String("Couldn't load external resource: "+path).utf8().get_data()); + if (r_res.is_null()) { + WARN_PRINT(String("Couldn't load external resource: "+path).utf8().get_data()); + } + } else { + r_res=RES(); } VariantParser::get_token(p_stream,token,line,r_err_str); @@ -597,6 +606,7 @@ void ResourceInteractiveLoaderText::get_dependencies(FileAccess *f,List open(f); + ignore_resource_parsing=true; ERR_FAIL_COND(error!=OK); while(next_tag.name=="ext_resource") { @@ -634,6 +644,7 @@ void ResourceInteractiveLoaderText::get_dependencies(FileAccess *f,List Error err = VariantParser::parse_tag(&stream,lines,error_text,next_tag,&rp); if (err) { + print_line(error_text+" - "+itos(lines)); error_text="Unexpected end of file"; _printerr(); error=ERR_FILE_CORRUPT; @@ -648,7 +659,7 @@ Error ResourceInteractiveLoaderText::rename_dependencies(FileAccess *p_f, const open(p_f,true); ERR_FAIL_COND_V(error!=OK,error); - + ignore_resource_parsing=true; //FileAccess FileAccess *fw = NULL; @@ -766,7 +777,7 @@ void ResourceInteractiveLoaderText::open(FileAccess *p_f,bool p_skip_first_tag) stream.f=f; is_scene=false; - + ignore_resource_parsing=false; resource_current=0; @@ -851,6 +862,8 @@ String ResourceInteractiveLoaderText::recognize(FileAccess *p_f) { stream.f=f; + ignore_resource_parsing=true; + VariantParser::Tag tag; Error err = VariantParser::parse_tag(&stream,lines,error_text,tag); diff --git a/scene/resources/scene_format_text.h b/scene/resources/scene_format_text.h index 02436a6e2d7..e5067ee7419 100644 --- a/scene/resources/scene_format_text.h +++ b/scene/resources/scene_format_text.h @@ -28,7 +28,7 @@ class ResourceInteractiveLoaderText : public ResourceInteractiveLoader { bool is_scene; String res_type; - + bool ignore_resource_parsing; // Map remaps;