pkdawson / imgui-godot

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

Android build (non-desktop) breaks addon #65

Open PerfectlyFineCode opened 2 weeks ago

PerfectlyFineCode commented 2 weeks ago

Android build breaks addon completely. From what I understand there's no way to use platform-specific code either. I have even added code to check for OS and/or feature flags to no avail. Still breaks. What can be done to fix this?

Godot Version v4.2.2.stable.official [15073afe3]

Addon Version 5.1.0

image

pkdawson commented 2 weeks ago

This plugin doesn't currently support Android (or iOS), though actually that's something I could probably do for GDScript and C++, just not C#.

This is a hacky solution, but it's the best I've got so far: use a feature flag, and then wherever you use ImGui, do this first:

var ImGui = ClassDB.instantiate("ImGui") # bad idea

You'll get a warning (SHADOWED_GLOBAL_IDENTIFIER), but the code should compile. It just has to be a local variable inside a function, not a member variable.

Actually this is a very bad solution, because it causes a significant memory leak.

Otherwise my notes here apply (I still need to update the documentation/examples): https://github.com/pkdawson/imgui-godot/discussions/62#discussioncomment-9630061

pkdawson commented 2 weeks ago

OK, better solution. Try this:

var ImGui = Engine.has_singleton("ImGuiGD")
if ImGui:
    ImGui.Begin("hello")
    ImGui.End()

You still get the warning, but no leaks and you shouldn't even need a feature flag.

I'll add a slightly better solution in the next version, which has the same drawbacks but is less weird and broken than exploiting a bool like this.

PerfectlyFineCode commented 2 weeks ago

OK, better solution. Try this:

var ImGui = Engine.has_singleton("ImGuiGD")
if ImGui:
    ImGui.Begin("hello")
    ImGui.End()

You still get the warning, but no leaks and you shouldn't even need a feature flag.

I'll add a slightly better solution in the next version, which has the same drawbacks but is less weird and broken than exploiting a bool like this.

Amazing! It worked. Thank you.