Why do Godot values diverge from the values obtained from a file?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By jitterbeetle

I read values from a file, calculate delta from previous to current and use draw_line in _draw from previous Vector2 to current Vector2. The Vector2 are stored in a list/array and all lines are redrawn at each interval.

But after a short time, a minute or so, the values in Godot diverge. I confirm accurate values from a python program.

I thought it might be some rounding like floor/ceiling but ruled that out and made sure I use floats.

Since I don’t know what’s going wrong I can only guess that there is some kind of caching or some math errors in Godot.

The calculation I do is simply:

(float(curr)-prev)/interval

Update #2:

After looking at this even more, it seems related to a bug(s). On github there are a few issues related to floats and Vector2 and this issue sort of matches what I am seeing. Vector floating point values are not matching what was assigned to it. · Issue #17971 · godotengine/godot · GitHub

Update #1:

I thought I found a work around. Instead of using the list/array of Vector2 and drawing all the lines from the Vector2 list/array at each interval, I found I can use:

get_viewport().set_clear_mode(Viewport.CLEAR_MODE_NEVER)
get_viewport().set_clear_mode(Viewport.CLEAR_MODE_ONLY_NEXT_FRAME)

which keeps the drawn lines and only refreshes if I need it. This way I only need
the previous Vector2 and the new Vector2.

But now I’ve encountered another feature or bug. If focus leaves the Godot
window no line drawing takes place and when focus is restored there are gaps
in the line. The gaps are equal in size to the amount of time focus was gone.

jitterbeetle | 2018-05-16 22:04