pkdawson / imgui-godot

Dear ImGui plugin for Godot 4
MIT License
318 stars 18 forks source link

Plots show invalid / near-zero values for floats (GDScript) #64

Closed PropFault closed 3 weeks ago

PropFault commented 3 weeks ago

Hi,

I have been trying to use this plugin to make a sort of fps-graph in godot for a few hours now and it seems that the plotting functions currently do not work as intended, or work in a way I fail to understand.

Expected Behavior: I input an array of godot floats (GDScript), the array reflects these values correctly and the correct values can be read.

Real Behavior: Only first value is shown correctly, rest of values are displayed as garbled floats (mostly small values in scientific notation on hover). image

Full code for widget:


var arr = []
var max_arr = 20
var update_timer = 0.0
var offset = 0
var highest = 60.0

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
    #offset = (offset + 1) % max(arr.size(),1)

    var average = 0.0
    for elem in arr:
        average = average + elem
        if(elem > highest):
            highest = elem
    average = (average / max(arr.size(),1))
    ImGui.Begin("UpdateTimer")
    ImGui.SetWindowSize(Vector2(0,0),ImGui.Cond_Always)
    ImGui.PlotHistogramEx("Frame Times", arr, arr.size(), offset, "Avg:" + ("%.2f" % average), 0.0, highest)
    ImGui.End()

    var monitor = snapped(Engine.get_frames_per_second(), 0.01)  
    arr.push_front(monitor)
    if(max_arr <= arr.size()):
        arr = arr.slice(1)

NOTE: I disabled the offset-scrolling in code for debug purposes. Also I noticed that the Plots do not update if the array is changed when im not offset-scrolling. Is this normal? I am not used to imgui

Please help me with this. I really like the idea of using this plugin to create plots for debug purposes, but right now i can not get it to work.

I tried setting the stride to 8 (8 bytes because GDScript uses doubles for all values I think) but that didnt help.

pkdawson commented 3 weeks ago

Thanks for reporting, there was indeed a bug in how the parameter was converted to a native array.

I updated the demo to be sure the histogram displays and updates correctly: https://github.com/pkdawson/imgui-godot/blob/master/doc/examples/GdsDemo/demo.gd

Fixed in v5.1.3