ImGuiNET / ImGui.NET

An ImGui wrapper for .NET.
MIT License
1.8k stars 298 forks source link

ImGui.PushStyleVar passes incorrect Y value for ImGuiStyleVar.WindowMinSize since version 1.90.0.0 #455

Closed NoahStolk closed 6 months ago

NoahStolk commented 6 months ago

Describe The Bug

I'm having a very strange bug since version 1.90.0.0. ImGuiStyleVar.WindowMinSize does not seem to work correctly anymore. Consider the following calls:

ImGui.PushStyleVar(ImGuiStyleVar.WindowMinSize, new Vector2(200, 500));
ImGui.Begin("Test");
ImGui.PopStyleVar();
ImGui.Text("Test");
ImGui.End();

This should force the window to not get smaller than 200x500 pixels. Instead, since version 1.90.0.0 it is possible to resize the window to a minimum of 200x200 pixels. You can easily reproduce this bug in ImGuiNET.SampleProgram.XNA, but not in ImGuiNET.SampleProgram.

ImGuiNET.SampleProgram.XNA:

image

Similarly, if we swap the values and pass a minimum of 500x200, it is not possible to make the window smaller than 500x500, so the Y value is ignored and X is used for both Vector2 components.

The strange part is that this does work correctly in the other ImGui.NET sample (the non-XNA one).

I've been debugging this bug for a couple hours but am unable to understand where exactly this is going wrong.

I've also made a very simple .NET 8 repo that demonstrates this problem: https://github.com/NoahStolk/WindowMinSize

image

In this repo you can quickly switch between versions 1.89.x and 1.90.x to see that this used to work correctly in 1.89.x, but not in 1.90.x.

Questions

  1. Does this happen for other ImGuiStyleVars where you're supposed to pass Vector2 values?
  2. Maybe this is a bug in ImGui itself or cimgui?

Workaround

Use ImGui.SetNextWindowSizeConstraints instead:

ImGui.SetNextWindowSizeConstraints(new Vector2(200, 500), new Vector2(float.MaxValue, float.MaxValue));
zaafar commented 6 months ago

you have to enable native debugging in order to figure out what's passed on c++/c side. read https://github.com/ImGuiNET/ImGui.NET#debugging-native-code to figure out how to enable that.

NoahStolk commented 6 months ago

you have to enable native debugging in order to figure out what's passed on c++/c side. read https://github.com/ImGuiNET/ImGui.NET#debugging-native-code to figure out how to enable that.

Thanks, that helps. Debugging the C++ shows the correct values:

image

But the bug persists. Also, because I'm now using cimgui.dll with debug symbols (compiled using ImGui.NET-nativebuild at tag v1.90), both samples now have the bug:

image

I didn't realize yesterday that I could query the WindowMinSize. Doing so gives me 32x32, which seems to be the default value defined in ImGui itself, I think:

image image

Maybe this is a problem with ImGui? It seems really weird that despite WindowMinSize being set to 32x32, I can't make the window smaller than 200x200, while passing 200x500.

I've also found a workaround; use SetNextWindowSizeConstraints instead of PushStyleVar(ImGuiStyleVar.WindowMinSize, ...):

ImGui.SetNextWindowSizeConstraints(new Vector2(200, 500), new Vector2(float.MaxValue, float.MaxValue));
zaafar commented 6 months ago

since correct value is reaching imgui, and its still wrong. I would say reach out to imgui folks and link this issue over there.

zaafar commented 6 months ago

oh look what I found https://github.com/ocornut/imgui/issues/7106

zaafar commented 6 months ago

also 1.90.1 changelog have this line