Skip to content
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

GetImGuiPtrs seems to be returning invalid pointer #93

Open
MrAdhit opened this issue Nov 14, 2024 · 1 comment · May be fixed by #95
Open

GetImGuiPtrs seems to be returning invalid pointer #93

MrAdhit opened this issue Nov 14, 2024 · 1 comment · May be fixed by #95

Comments

@MrAdhit
Copy link

MrAdhit commented Nov 14, 2024

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
Copy link
Author

MrAdhit commented Nov 15, 2024

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

@MrAdhit MrAdhit linked a pull request Nov 15, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant