Fix Ref leak when using Godot getters
parent
9ed6edaae1
commit
ac0679eb1a
|
@ -346,7 +346,7 @@ def generate_class_implementation(icalls, used_classes, c):
|
||||||
if is_enum(method["return_type"]):
|
if is_enum(method["return_type"]):
|
||||||
return_statement += "return (" + remove_enum_prefix(method["return_type"]) + ") "
|
return_statement += "return (" + remove_enum_prefix(method["return_type"]) + ") "
|
||||||
elif is_reference_type(method["return_type"]):
|
elif is_reference_type(method["return_type"]):
|
||||||
return_statement += "return Ref<" + strip_name(method["return_type"]) + ">(";
|
return_statement += "return Ref<" + strip_name(method["return_type"]) + ">::__internal_constructor(";
|
||||||
else:
|
else:
|
||||||
return_statement += "return " + ("(" + strip_name(method["return_type"]) + " *) " if is_class_type(method["return_type"]) else "")
|
return_statement += "return " + ("(" + strip_name(method["return_type"]) + " *) " if is_class_type(method["return_type"]) else "")
|
||||||
else:
|
else:
|
||||||
|
@ -414,7 +414,7 @@ def generate_class_implementation(icalls, used_classes, c):
|
||||||
cast = ""
|
cast = ""
|
||||||
if is_class_type(method["return_type"]):
|
if is_class_type(method["return_type"]):
|
||||||
if is_reference_type(method["return_type"]):
|
if is_reference_type(method["return_type"]):
|
||||||
cast += "Ref<" + stip_name(method["return_type"]) + ">::__internal_constructor(__result);"
|
cast += "Ref<" + strip_name(method["return_type"]) + ">::__internal_constructor(__result);"
|
||||||
else:
|
else:
|
||||||
cast += "(" + strip_name(method["return_type"]) + " *) (Object *) __result;"
|
cast += "(" + strip_name(method["return_type"]) + " *) (Object *) __result;"
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -199,6 +199,15 @@ public:
|
||||||
|
|
||||||
unref();
|
unref();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Used exclusively in the bindings to recreate the Ref Godot encapsulates in return values,
|
||||||
|
// without adding to the refcount.
|
||||||
|
inline static Ref<T> __internal_constructor(Object *obj)
|
||||||
|
{
|
||||||
|
Ref<T> r;
|
||||||
|
r.reference = (T*)obj;
|
||||||
|
return r;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue