1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-05 12:10:55 +00:00

Fix base script not initialized properly in some cases

Storing script references to pointer only in result.script_type could
lead to losing the last reference, causing further conversions from
Script* to Ref<Script> to fail.

Now result.script_type_ref is always set first, and then cleared in the
specific case of the script being the owner, to avoid cyclic reference
issues.

(cherry picked from commit 87d73faa66)
This commit is contained in:
PouleyKetchoupp
2020-12-04 10:58:59 -07:00
committed by Rémi Verschelde
parent 94fff8abb9
commit 9d2c012f23

View File

@@ -130,7 +130,8 @@ GDScriptDataType GDScriptCompiler::_gdtype_from_datatype(const GDScriptParser::D
} break;
case GDScriptParser::DataType::SCRIPT: {
result.kind = GDScriptDataType::SCRIPT;
result.script_type = Ref<Script>(p_datatype.script_type).ptr();
result.script_type_ref = Ref<Script>(p_datatype.script_type);
result.script_type = result.script_type_ref.ptr();
result.native_type = result.script_type->get_instance_base_type();
} break;
case GDScriptParser::DataType::GDSCRIPT: {
@@ -159,7 +160,8 @@ GDScriptDataType GDScriptCompiler::_gdtype_from_datatype(const GDScriptParser::D
}
result.kind = GDScriptDataType::GDSCRIPT;
result.script_type = Ref<Script>(script).ptr();
result.script_type_ref = Ref<Script>(script);
result.script_type = result.script_type_ref.ptr();
result.native_type = script->get_instance_base_type();
} break;
default: {
@@ -170,8 +172,8 @@ GDScriptDataType GDScriptCompiler::_gdtype_from_datatype(const GDScriptParser::D
// Only hold strong reference to the script if it's not the owner of the
// element qualified with this type, to avoid cyclic references (leaks).
if (result.script_type && result.script_type != p_owner) {
result.script_type_ref = Ref<Script>(result.script_type);
if (result.script_type && result.script_type == p_owner) {
result.script_type_ref = Ref<Script>();
}
return result;