-
-
Notifications
You must be signed in to change notification settings - Fork 22k
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
Animation.get_length() doesn't return correct value #52127
Comments
@aaronfranke Can you help me describe the nature of floating point exact equality comparisons? I remember there was a blog post somewhere. |
@fire We should not use float exact equality comparisons, instead we use |
It looks like there's a minimum of godot/scene/resources/animation.cpp Lines 2474 to 2480 in f89adbf
That explains the last case, and it should be the case on both 3.x and 4.0. |
If all the cases are covered and explained, I don't think we have incorrect values. That suggests we can close this bug. |
Yes, these values are expected. There is no bug here unless we want to support animation lengths < 0.001. |
I made a bad description of the issue. I modified the code a bit to make it clearer. New code: randomize()
for anim in anim_player.get_animation_list():
var frame_count : float = randi() % 20 + 1
var frame_fps : float = randi() % 10 + 1
var anim_length = round(frame_count / frame_fps * 1000.0) / 1000.0
anim_player.get_animation(anim).set_length(anim_length)
var actual_length = anim_player.get_animation(anim).get_length()
print("Set length ", anim_length, ", actual length ", actual_length)
print("Actual length is larger than the set length : ", actual_length > anim_length)
print(" ") In 4.0:
In 3.x:
|
The difference in the printed values probably comes from #21922, which changed |
@floppyhammer Every one of those examples is due to floating point error. You have to compare using I'm not sure if you deliberately did this, but pay special attention to the values you're using. All of the ones at the bottom are perfectly representable with floats because they are sums of powers of two (ex: 0.625 = 0.5 + 0.125). These numbers will also be exact in 4.0. On the other hand, a number ending in 0.333 cannot be represented perfectly with floats so it's expected to have imprecision. We can get closer by increasing float precision (compiling with Since the bug you've encountered is expected float imprecision and there is no feature request or confusion about zero-length animations, there is nothing that can be done here, so I'm closing this. |
Godot version
v4.0.dev.custom_build [6e87d62]
System information
Windows 11, Vulkan Clustered
Issue description
Animation.get_length()
doesn't return correct value. The issue doesn't occur to 3.x.Output:
Steps to reproduce
Run the scene in the minimal project.
Minimal reproduction project
Animation Length.zip
The text was updated successfully, but these errors were encountered: