ImGuiNET / ImGui.NET

An ImGui wrapper for .NET.
MIT License
1.85k stars 300 forks source link

Invalid generations with latest cimgui #168

Open ff-meli opened 4 years ago

ff-meli commented 4 years ago

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.

Sewer56 commented 4 years ago

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:

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.

ChristianIvicevic commented 4 years ago

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 😃

giulianob commented 4 years ago

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?