ImGuiNET / ImGui.NET

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

using ImGuiListClipperPtr triggers AccessViolationException after upgrading to 1.89 #401

Closed pixtur closed 1 year ago

pixtur commented 1 year ago

Hi,

after upgrading to v1.89.5 the following code causes as System.AccessViolationException:


  unsafe
  {
      var clipperData = new ImGuiListClipper();
      var listClipperPtr = new ImGuiListClipperPtr(&clipperData);
      listClipperPtr.Begin(items.Count, ImGui.GetTextLineHeightWithSpacing());
   }

Maybe I'm using the API in an unintended way, but it I assume something changed in the implementation. This could also be on the ImGui side, but I'm not good enough with C to write an example.

zaafar commented 1 year ago

was it working before 1.89.5?

pixtur commented 1 year ago

after upgrading to 1.89

Good point I only tested 1.88.0 and 1.87.3. v1.88 also triggers the exception. v1.87.3 works.

I know it's kind of too much work to ask for, but these were me steps to reproduce:

  1. clone https://github.com/still-scene/t3/tree/dev
  2. Upgrade nuget package
  3. Start Editor and then open Window -> Console from Tooll's app menu.
zaafar commented 1 year ago

I just tested imgui.net version 1.89.4 (which points to cimgui 1.89.2) and its working fine. Looks like it broke in the last upgrade (i.e. imgui.net version 1.89.5 which points to cimgui 1.89.5).

i will dig more and try to figure out what changed between these 2 versions that broke it...

zaafar commented 1 year ago

the only thing that changed was as following. image

zaafar commented 1 year ago

==debugging+fixing the issue==

-> lets go into this function image

-> lets go into this function image

-> lets go into this cimgui (c language) function. image

-> according to this c++ (imgui function), looks like Ctx isn't initialized and it is suppose to be. image

zaafar commented 1 year ago

==solution==

i am not sure if this is how we should do it....or if this is the right ctx to use but this is one possible solution.

image

zaafar commented 1 year ago

interesting read: https://github.com/ocornut/imgui/commit/c8ad25caa6bfcb786085a76e67a7f31e61a80cb7 -> https://github.com/ocornut/imgui/pull/5856

pixtur commented 1 year ago

Oh wow. Thanks for looking into that so quickly! I'm not in a rush to upgrade, so I can wait until there is a final fix.

zaafar commented 1 year ago

the workaround is here (https://github.com/ImGuiNET/ImGui.NET/issues/401#issuecomment-1566216444) if you want to use that while waiting for a final fix.

TheLostTree commented 1 year ago

https://github.com/ImGuiNET/ImGui.NET/issues/393#issuecomment-1528692332 this should work also

zaafar commented 1 year ago

If you do that, you have to call the c++ destructor function as well. Just FYI.

ocornut commented 1 year ago

I have also pushed a workaround on dear imgui side: https://github.com/ocornut/imgui/commit/e95d66faa8e6c0255572632f34fad97a32f680cd

zaafar commented 1 year ago

Closing this issue as it will be fixed automatically once imgui.net is upgraded to the latest (unreleased) version.