-
-
Notifications
You must be signed in to change notification settings - Fork 10.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Memory allocation/dealloc problem in imgui_demo.cpp #538
Comments
There was one fix applied on Nov 5 but you have never answered the request for details in the old thread: What exactly is the issue? I would appreciate a more detailed explanation. Can't you have construct/destruct allocators matching? Is fixing imgui_demo for the case of using a custom allocator actually useful? The one in line 716 could be replaced with a normal array + bool since the size is static. There's however at least another one in the custom drawing demo. EDIT Also see #396 |
yeah, sorry for that, I got the bug and reported it but never had the time to get to it later on
Yes, as I said in my post, this is a minor thing and not really affecting the imgui usage. But the demos will crash if you want to use them in your app with custom allocators. You could also define them as a global var and clear them on Imgui::Shutdown, if you like the code to be working correctly in every scenario thanks |
You still aren't explaining which sequence of allocator-assignment/allocation/free is leading to crash. |
You can reproduce the bug by :
The program will crash because the custom allocator is destroyed, after that, the |
I have fixed this instance of use of ImVector because it's more common to run this code when using the demo. However the Log, Console and Custom Drawing demo are using ImVector<> as well and wouldn't as easily be converted. Normally you would keep your allocator active so it function during static destruction. I am not sure how you would suggest to fix the other instances of heap use in the demo in way that wouldn't be detrimental to the demo code. NB: ImGui::Shutdown() doesn't affect anything used by the demo code which is standalone. |
@septag Ping? can you keep your allocator active during static destruction? is using the demo code with your custom allocator a requirement? can you suggest a solution? (see: Log/Console/CustomDrawing demos). |
my allocator is a static global itself. but I think the compiler doesn't guarantee which static variable gets destructed first when program exits.
Not at all. I'm just doing this for testing purposes in my engine. it's not a permanent thing at all. I was just pointing out that It's a bad practice doing these stuff in the ImGui code and may raise problems with some users.
An easy and convenient way would be adding |
I suppose the idea of keeping your allocator active during static destruction is that it would NOT have a destructor. Each of the individual demo is independent and there's no high-level encompassing structure, code/data are as local as possible so that the example as easy to follow. This is also why most examples are using local static variables for storage. To implement ShutdownDemos() correctly I would have to pull out all e.g. I would prefer to pass since it isn't a blocking issue, it only affects actively using the demos, we have fixed the most common culprit (the plotting demo that was more common click away) and using custom allocators is really uncommon. If I were to fix it it would alter demo code readability for what is essentially a very rare use case. If you aren't comfortable with not destroying your allocator and still want to seldomly use the stock log/consoles/drawing demos within your application you can either bear the crash on quitting or skip destroying your allocator only if imgui demos have been used. |
TLDR; you are right but i don't have a satisfying solution without butchering the demo. I'm hoping my suggestions above are good enough of a workaround. |
I think I've submitted this before. Although it's a minor thing, but it raises problems when using custom allcoators and ShowTestWindow() function.
There is a static ImVector decleration in imgui_demo.cpp@716 That causes the ImVector destructor to crash on program exit.
Is there any workarounds for this, instead of using static declerations ?
thanks
The text was updated successfully, but these errors were encountered: