diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2023-01-05 12:56:53 +0100 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2023-01-05 12:56:53 +0100 |
commit | d322c154a6be5b9739e47b9596008d86c8d586dd (patch) | |
tree | 3fe590e469ac5115df9d7c32df0772e845ec79f7 | |
parent | d29193affe7b9e2ce2a88e86c1731ea3b8ccd5d6 (diff) | |
parent | a6e02f149f14ce18864af7a62d81e816710f8a4a (diff) |
Merge pull request #70795 from KoBeWi/TweenCounted
Improve `RefCounted` support in `Tween`
-rw-r--r-- | scene/animation/tween.cpp | 14 | ||||
-rw-r--r-- | scene/animation/tween.h | 6 |
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 |