From 7725ebf3d2e7a988ce24aded5e081b0afac76fe5 Mon Sep 17 00:00:00 2001 From: George Marques Date: Mon, 4 Oct 2021 20:46:35 -0300 Subject: GDScript: Use path cache when checking preloaded scripts The path itself might not always be set in some cases, especially when the script is just created and is already in the resource cache. Using get_path() in this case gets the correct resource path. This also adds a null check for safety in case the path is incorrect or missing, to avoid a crash in the engine. --- modules/gdscript/gdscript_analyzer.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/modules/gdscript/gdscript_analyzer.cpp b/modules/gdscript/gdscript_analyzer.cpp index ac031baa8c..c07849bfa8 100644 --- a/modules/gdscript/gdscript_analyzer.cpp +++ b/modules/gdscript/gdscript_analyzer.cpp @@ -3305,7 +3305,13 @@ GDScriptParser::DataType GDScriptAnalyzer::type_from_variant(const Variant &p_va current = current->_owner; } - Ref ref = get_parser_for(current->path); + Ref ref = get_parser_for(current->get_path()); + if (ref.is_null()) { + push_error("Could not find script in path.", p_source); + GDScriptParser::DataType error_type; + error_type.kind = GDScriptParser::DataType::VARIANT; + return error_type; + } ref->raise_status(GDScriptParserRef::INTERFACE_SOLVED); GDScriptParser::ClassNode *found = ref->get_parser()->head; -- cgit v1.2.3