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

BeginPopupModal can not call with nullptr for the parameter p_open

Open zcyemi opened this issue 6 years ago • 2 comments

Hi mellinoe, I'm encountering problems when creating a popupModal without close button on the headerbar but include ImGuiWindowFlags. The cimgui method can transfer the second parameter bool* with null. But the C# API for the second parameter is ref bool, so I can't call it with null. Current method overloading:

BeginPopupModal(string name)
BeginPopupModal(string name, ref bool p_open)
BeginPopupModal(string name, ref bool p_open, ImGuiWindowFlags flags)

And there are two solutions:

  • add new method overloading BeginPopupModal(string name, ImGuiWindowFlags flags), set the second parameter with byte* native_p_open = null;
  • change ref bool to ref bool?, then modifing the codegenerator implement.

What do you think? Are there any other solution can help?

zcyemi avatar Sep 01 '19 04:09 zcyemi

change ref bool to ref bool?, then modifing the codegenerator implement.

Personally, I think this is confusing, because you aren't passing a reference to a null value -- you want the reference itself to be null. Unfortunately, C# ref parameters aren't exactly what we want, because they can't be null. Technically, you can pass a null reference by doing something like ref Unsafe.AsRef<bool>(null) as the parameter, but that's very sketchy.

add new method overloading BeginPopupModal(string name, ImGuiWindowFlags flags), set the second parameter with byte* native_p_open = null;

This seems like a good compromise. I think it's reasonable to include it in the "Manual" overloads file, although adding anything in there has a decent maintenance burden (since it can fall out of sync with the rest of the auto-generated library).

Unfortunately, it's not straightforward to use actual C# optional parameters for most of the native functions, because a lot of them include default vector params, which can't be represented in C#.

mellinoe avatar Sep 16 '19 06:09 mellinoe

The ref parameters can be null. Since there are these fancy method Unsafe.NullRef<T>() and Unsafe.IsNullRef<T>(). I feel like it's just limiting the full potential usage of ImGui.

Zexyp avatar Nov 29 '23 22:11 Zexyp