Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent errors if Tween callback's object is freed #81127

Merged
merged 1 commit into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/classes/CallbackTweener.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
</brief_description>
<description>
[CallbackTweener] is used to call a method in a tweening sequence. See [method Tween.tween_callback] for more usage information.
The tweener will finish automatically if the callback's target object is freed.
[b]Note:[/b] [method Tween.tween_callback] is the only correct way to create [CallbackTweener]. Any [CallbackTweener] created manually will not function correctly.
</description>
<tutorials>
Expand Down
1 change: 1 addition & 0 deletions doc/classes/MethodTweener.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
</brief_description>
<description>
[MethodTweener] is similar to a combination of [CallbackTweener] and [PropertyTweener]. It calls a method providing an interpolated value as a parameter. See [method Tween.tween_method] for more usage information.
The tweener will finish automatically if the callback's target object is freed.
[b]Note:[/b] [method Tween.tween_method] is the only correct way to create [MethodTweener]. Any [MethodTweener] created manually will not function correctly.
</description>
<tutorials>
Expand Down
8 changes: 8 additions & 0 deletions scene/animation/tween.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,10 @@ bool CallbackTweener::step(double &r_delta) {
return false;
}

if (!callback.get_object()) {
return false;
}

elapsed_time += r_delta;
if (elapsed_time >= delay) {
Variant result;
Expand Down Expand Up @@ -736,6 +740,10 @@ bool MethodTweener::step(double &r_delta) {
return false;
}

if (!callback.get_object()) {
return false;
}

elapsed_time += r_delta;

if (elapsed_time < delay) {
Expand Down
Loading