summaryrefslogtreecommitdiffstats
path: root/core/variant/callable.cpp
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2024-10-02 15:00:47 +0200
committerRémi Verschelde <rverschelde@gmail.com>2024-10-02 15:00:47 +0200
commit9ce149c7a3cd940d734ec50a4ce78d246d0012ef (patch)
tree2cd3ab2c1dee386225c8937fe50df6ef46010952 /core/variant/callable.cpp
parent7f1f9799c5955af4e29ecb7d4d3d765ad36f5beb (diff)
parentcee0e6667a2583a128ab3de33ab43f06222c4ca9 (diff)
downloadredot-engine-9ce149c7a3cd940d734ec50a4ce78d246d0012ef.tar.gz
Merge pull request #93299 from rune-scape/fix-ref
Fix RefCounted releasing early and not clearing reference
Diffstat (limited to 'core/variant/callable.cpp')
-rw-r--r--core/variant/callable.cpp19
1 files changed, 10 insertions, 9 deletions
diff --git a/core/variant/callable.cpp b/core/variant/callable.cpp
index bb2d0313f6..5ce90cd8ff 100644
--- a/core/variant/callable.cpp
+++ b/core/variant/callable.cpp
@@ -315,31 +315,32 @@ bool Callable::operator<(const Callable &p_callable) const {
}
void Callable::operator=(const Callable &p_callable) {
+ CallableCustom *cleanup_ref = nullptr;
if (is_custom()) {
if (p_callable.is_custom()) {
if (custom == p_callable.custom) {
return;
}
}
-
- if (custom->ref_count.unref()) {
- memdelete(custom);
- custom = nullptr;
- }
+ cleanup_ref = custom;
+ custom = nullptr;
}
if (p_callable.is_custom()) {
method = StringName();
- if (!p_callable.custom->ref_count.ref()) {
- object = 0;
- } else {
- object = 0;
+ object = 0;
+ if (p_callable.custom->ref_count.ref()) {
custom = p_callable.custom;
}
} else {
method = p_callable.method;
object = p_callable.object;
}
+
+ if (cleanup_ref != nullptr && cleanup_ref->ref_count.unref()) {
+ memdelete(cleanup_ref);
+ }
+ cleanup_ref = nullptr;
}
Callable::operator String() const {