Skip to content

Calling Tween.custom_step() from within a tween freezes the game and produces an unclear fatal C++ error #99441

Closed
@HeySora

Description

@HeySora

Tested versions

  • Reproducible in v4.3.stable.mono.official [77dcf97]

System information

Godot v4.3.stable.mono - macOS 15.0.1 - Vulkan (Forward+) - integrated Apple M3 Max - Apple M3 Max (14 Threads)

Issue description

While I'm aware that calling CustomStep() from within a tween can be undefined behavior (I would understand if that particular edge case would be a wontfix!), I still think that a clearer error should be printed, and the game should definitely not freeze.

When CustomStep() is called, this gets printed right before the program crashes:

ERROR: FATAL: Index p_index = 4 is out of bounds (((Vector<T> *)(this))->_cowdata.size() = 3).
   at: operator[] (./core/templates/vector.h:52)

("3" is the amount of tweeners, so it may vary depending on the amount of queued tweens)

Avoiding this issue is as easy as wrapping the CustomStep() call inside a Callable + with CallDeferred().

Steps to reproduce

The smallest code that can crash the game and trigger the above error is:

bool finished = false;
Tween tween = GetTree().CreateTween();
tween.TweenCallback(Callable.From(() =>
{
    if (finished) return;
    finished = true;

    tween.CustomStep(1e9);
}));

(the finished bool is to prevent a stack overflow which would be happening because of that particular tween being called again over and over)

Replacing tween.CustomStep(1e9); with Callable.From(() => { tween.CustomStep(1e9); }).CallDeferred() is enough to fix the issue.

Minimal reproduction project (MRP)

MRP-TweenCrash.zip
(Please note that the error might not even be visible from the Godot editor; you might need to run the game via the terminal or an editor like e.g. Jetbrains Rider)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions