ImGui.NET icon indicating copy to clipboard operation
ImGui.NET copied to clipboard

Invalid generations with latest cimgui

Open ff-meli opened this issue 4 years ago • 3 comments

As noted in #167, the latest cimgui (master, hash be187bcdc43b124250f7c0f6b4c216a4094053b1) generates successfully, but ImGui.NET can't handle the results.

After fixing size expression parsing as mentioned in that issue, there are a few type-generation issues. I wasn't sure of the correct way to resolve these, but adding this to s_wellKnownTypes in CodeGenerator's Program.cs "seems" to at least generate more compile-able code:

{ "unsigned char[256]", "byte*" },
{ "signed char", "sbyte" },
{ "ImS8", "sbyte" },
{ "ImU8", "byte" },
{ "ImU64", "UInt64" }

There are other missing types that are used - the compiler gave up too soon for me to catch many things.

A number of classes generate a huge number of errors because they fail to compile for a dozen reasons, making it difficult to tell which are the actual errors.

There are also still issues with some unions, which just seem to get copied directly, leading to generated code like this: public ref union { int BackupInt[2]; float BackupFloat[2];} => ref Unsafe.AsRef<union { int BackupInt[2]; float BackupFloat[2];}>(&NativePtr->); (in ImGuiStyleMod.gen.cs)

I noticed s_customDefinedTypes and how that is used for manual types, but I wasn't sure if that was necessary/the correct approach here.

I think having imgui_internal generation turned on (which is now the default) causes even more problems along these same lines, but many of these errors are present without it. It would also be nice to be able to generate with that enabled.

Is there any information or guidelines about how to fix up the generator? I'd like to try to get things working, ideally without just hacking everything to pieces.

ff-meli avatar May 03 '20 23:05 ff-meli

While the DLLs shipped with the latest build are 1.75, the generator wasn't ran with the same version? This often causes undefined function errors as the exported functions don't match due to API changes.

I've made some personal progress in getting 1.75+ to work, though I'm still a while away. https://github.com/Sewer56/ImGui.NET/commit/9b4bf4ea2cfefc72d9ce9c6044ae51ea9e2eb690

If anything, for now, this is a starting point.

Remaining Issues:

  • Generics with non-ImVector
  • Delegates in structs.

Delegates are output by the code generator but this behaviour's incorrect because while they can be marshalled, delegates are not blittable. If it's a delegate, an IntPtr should be generated instead and a getter which converts the IntPtr to a delegate using Marshal.GetFunctionPointerForDelegaet should be added.

Sewer56 avatar May 26 '20 05:05 Sewer56

The current issue with the generation was the reason why I had issues using the docking branch of ImGui.NET with the newest manually built cimgui library copied over. Due to wrong pointers some styling got botched (surprisingly enough docking worked perfectly). I'd be glad if this issue with the generator can be resolved anytime soon so that I can use the latest builds again.

Thank you for your efforts looking into this so far 😃

ChristianIvicevic avatar May 29 '20 01:05 ChristianIvicevic

I'm completely out of my depth here but I'm also wanting to build latest imgui and I'm wondering if using something like https://github.com/mono/CppSharp would be a good alternative? Does anyone have experience with using that to bridge to low level code and whether it works well and how straight forward it is?

giulianob avatar Jun 02 '20 13:06 giulianob