pkdawson / imgui-godot

Dear ImGui plugin for Godot 4
MIT License
494 stars 28 forks source link

`GetImGuiPtrs` seems to be returning invalid pointer #93

Open MrAdhit opened 2 weeks ago

MrAdhit commented 2 weeks ago

Hey,

So I'm trying to use this plugin on my Rust backend with gdext, I can call GetImGuiPtrs perfectly fine, but when it comes to setting the current imgui context with the pointer returned by that function, it seems that the pointer is actually invalid, it's just pointing to a garbage memory, and when I try to destroy it (just to figure out if it's actually ImGuiContext* or not), the whole app just crashes.

Here's the code that I wrote.

        let obj = ClassDb::singleton().instantiate("ImGuiSync");

        unsafe {
            let ptrs: PackedInt64Array = obj.call("GetImGuiPtrs", &[
                Variant::from(CStr::from_ptr(ImGui::GetVersion()).to_str().unwrap()),
                Variant::from(size_of::<ImGuiIO>() as i32),
                Variant::from(size_of::<ImDrawVert>() as i32),
                Variant::from(size_of::<ImDrawIdx>() as i32),
                Variant::from(size_of::<ImWchar>() as i32),
            ]).to();

            ImGui::DestroyContext(transmute(ptrs[0]));
        }

I use this example , this, and this for reference So I assume that I need to call GetImGuiPtrs

MrAdhit commented 2 weeks ago

Ah, it was because I didn't define IMGUI_USER_CONFIG. After defining it like

.define("IMGUI_USER_CONFIG", "\"imconfig-godot.h\"")

when compiling ImGui with cc, everything seems to be working correctly.

I'll create an example Rust project to document this