dearimgui / dear_bindings

C header (and language binding metadata) generator for Dear ImGui
MIT License
221 stars 12 forks source link

Output is missing fields from conditional groups [2] #61

Closed paralaxsd closed 7 months ago

paralaxsd commented 7 months ago

Hi,

I've found today that for newest versions of Dear Bindings [711dc5f] and Dear ImGui docking branch [ce0d0ac], both projects freshly cloned into sibling directories, generating default json output via

python dear_bindings.py -o cimgui ..\imgui\imgui.h

would create data where certain field members that are part of a conditional group are missing.

Example: the ImGuiIO struct contains the following fields:

#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
    void*       ImeWindowHandle;                    // = NULL   // [Obsoleted in 1.87] Set ImGuiViewport::PlatformHandleRaw instead. Set this to your HWND to get automatic IME cursor positioning.
#else
    void*       _UnusedPadding;
#endif
    ImGuiContext* Ctx; 

I'd expect an entry for _UnusedPadding in the json output but only ImeWindowHandle is included, followed directly by Ctxt.

I couldn't unfortunately bisect the issue as earlier commits are having a hard time with current Dear ImGui code but perhaps referring to the similar issue #28 that's been fixed previously can be of help!

Edit:
I had another look, running against Dear ImGui v1.89.9 which retains the conditional grouping from above and it seems to me now that _UnusedPadding was actually missing from the output since after 759c901. Even the fix from #28 does not reintroduce it if I run dear bindings from back then today. When I confirmed the fix it seems I didn't notice since I did not disable obsolete functions and so the ImGuiIOstruct regained its correct size via the ImeWindowHandle field.

ShironekoBen commented 7 months ago

Yeah, that definitely sounds like a bug in the preprocessor conditional parsing. Thanks for the report - I'm afraid I'm a little snowed under right now but I'll take a look in a couple of days and see if I can figure out what's going wrong!

paralaxsd commented 7 months ago

No worries, I'm glad if this helps the project a bit which already has helped me tremendously.

For the time being, my v1.90 upgrade efforts are resting comfortably in their own branch until ready for prime time :)

ShironekoBen commented 7 months ago

OK, I had a look and it was a silly mistake where the field emitting code didn't correctly recurse into the 'else' clause of preprocessor conditionals when writing the metadata. Hopefully 79e88f824161a39d56255cdc5dc3bad06871b46d should fix this - let me know if you spot any other issues with this! Thanks again for the help!

paralaxsd commented 7 months ago

Hi Ben, thanks for the fix!

I now can generate working C# bindings for Dear ImGui v1.90 and my bindings also no longer depend on obsoleted functionality so I'm quite happy with the progress on that front.