pkdawson / imgui-godot

Dear ImGui plugin for Godot 4
MIT License
423 stars 24 forks source link

Minimizing windows with tables causes a crash #63

Closed ckyb closed 4 months ago

ckyb commented 4 months ago

When using a table, minimizing the imgui window causes a crash with no debug log or stack trace.

Versions

Minimal Reproduction

extends Node

var myfloat := [0.0]
var mystr := [""]

func _ready():
    var io := ImGui.GetIO()
    io.ConfigFlags |= ImGui.ConfigFlags_ViewportsEnable

func _process(_delta):
    ImGui.Begin("hello")

    ImGui.BeginTable("Table1", 2)
    ImGui.TableSetupColumn("hello")
    ImGui.TableSetupColumn("world")
    ImGui.TableHeadersRow()

    ImGui.EndTable()

    ImGui.End()
pkdawson commented 4 months ago

I can reproduce the crash, but you should see an error like: ERROR: IM_ASSERT table != NULL && "Need to call TableSetupColumn() after BeginTable()!" (imgui/imgui_tables.cpp:1528)

If you don't, that's a bug. I admit I haven't really tested on Linux at all.

You want to check that BeginTable returns true before adding stuff to the table. Like:

    if ImGui.BeginTable("Table1", 2):
        ImGui.TableSetupColumn("hello")
        ImGui.TableSetupColumn("world")
        ImGui.TableHeadersRow()
        ImGui.EndTable()

See eg, https://github.com/ocornut/imgui/blob/e391fe2e66eb1c96b1624ae8444dc64c23146ef4/imgui_demo.cpp#L621-L636

ckyb commented 4 months ago

I didn't see an error, but that was indeed the cause of the crash - the table needs to be wrapped in an if block to ensure setting up the table can succeed (like your example).

Closing this issue as operator error - thank you for pointing that out!