summaryrefslogtreecommitdiff
path: root/scene/animation
diff options
context:
space:
mode:
authorkobewi <kobewi4e@gmail.com>2023-01-01 11:27:53 +0100
committerkobewi <kobewi4e@gmail.com>2023-01-01 18:45:17 +0100
commita6e02f149f14ce18864af7a62d81e816710f8a4a (patch)
tree332a172aa7030eda8353a3477899b648d2d8e3ee /scene/animation
parent8a98110e3e353a9a3b86b4a0bd56adf405bd6d93 (diff)
Improve RefCounted support in Tween
Diffstat (limited to 'scene/animation')
-rw-r--r--scene/animation/tween.cpp14
-rw-r--r--scene/animation/tween.h6
2 files changed, 20 insertions, 0 deletions
diff --git a/scene/animation/tween.cpp b/scene/animation/tween.cpp
index aa58e1044a..448b9e9ad2 100644
--- a/scene/animation/tween.cpp
+++ b/scene/animation/tween.cpp
@@ -563,6 +563,10 @@ PropertyTweener::PropertyTweener(Object *p_target, NodePath p_property, Variant
base_final_val = p_to;
final_val = base_final_val;
duration = p_duration;
+
+ if (p_target->is_ref_counted()) {
+ ref_copy = p_target;
+ }
}
PropertyTweener::PropertyTweener() {
@@ -640,6 +644,11 @@ void CallbackTweener::_bind_methods() {
CallbackTweener::CallbackTweener(Callable p_callback) {
callback = p_callback;
+
+ Object *callback_instance = p_callback.get_object();
+ if (callback_instance && callback_instance->is_ref_counted()) {
+ ref_copy = callback_instance;
+ }
}
CallbackTweener::CallbackTweener() {
@@ -728,6 +737,11 @@ MethodTweener::MethodTweener(Callable p_callback, Variant p_from, Variant p_to,
delta_val = Animation::subtract_variant(p_to, p_from);
final_val = p_to;
duration = p_duration;
+
+ Object *callback_instance = p_callback.get_object();
+ if (callback_instance && callback_instance->is_ref_counted()) {
+ ref_copy = callback_instance;
+ }
}
MethodTweener::MethodTweener() {
diff --git a/scene/animation/tween.h b/scene/animation/tween.h
index 345974ecc5..4b69dc337c 100644
--- a/scene/animation/tween.h
+++ b/scene/animation/tween.h
@@ -208,6 +208,8 @@ private:
Variant final_val;
Variant delta_val;
+ Ref<RefCounted> ref_copy; // Makes sure that RefCounted objects are not freed too early.
+
double duration = 0;
Tween::TransitionType trans_type = Tween::TRANS_MAX; // This is set inside set_tween();
Tween::EaseType ease_type = Tween::EASE_MAX;
@@ -249,6 +251,8 @@ protected:
private:
Callable callback;
double delay = 0;
+
+ Ref<RefCounted> ref_copy;
};
class MethodTweener : public Tweener {
@@ -280,6 +284,8 @@ private:
Variant delta_val;
Variant final_val;
Callable callback;
+
+ Ref<RefCounted> ref_copy;
};
#endif // TWEEN_H