-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
Calling MemFree after an explicit destruction of the last context #992
Comments
Can you confirm that you are getting the bug when running the unmodified sample from the There's no code afaik that explicitly set GImGui to NULL. |
no it work, its weird, i have replace all the imgui and the interface with sdl2 from my app in the example and it work. but im not sure why i created a context :), i find that in a sample on the net. what is the goal to create a imgui context ? |
it was for a multi windows system. how can i destroy the current context properly ? it is necessary ? |
Hmm. Right now the easiest workaround is to never destroy the initial/default context. It's an issue with the design of storing those I chose to put them in the context to avoid relying on I think I might just bite the bullet and move to global functions, aka GImGuiMalloc, GImGuiFree ? Moving this discussion to #586 |
for the moment, i not used the many context. and the bug appear only with the use of ctrl+v, so for the moment, i can wait a fix :) thanks, for the explains |
It is not happening for destroying default context, just destroying any context sets GImGui to NULL. |
How come unmodified sample hasn't got this issue then? |
unmodified sample only uses default context |
I've been running into a sporadic crash on shutdown in a Windows codebase that uses a non-default context. The code lives inside a DLL, so context lifetime is tied to when the DLL loads and unloads, but static variables are only destructed at process exit which happens after the DLL is unloaded... The callstack points at the destructor for this variable:
I've locally changed it so it always uses a I haven't done substantial testing to confirm if that fixes my problem, but does that seem like a reasonable change to make? |
@zx64 Well it would work but it is a little odd and misleading. That clipboard function should have nothing to do with an imgui context and you are using a buffer than happens to be lying in a context, so it ties the lifetime of the return value to the context. Practically speaking it is probably ok but it feels very misleading.
If I understand correctly the problem is that at the time of destruction ImVector<> cannot access a destructor since it is stored in the current GImGui instance pointer? If that's the case you might also be able to temporarily workaround by restoring the default context after destroying your context. (I suppose I should bite the bullet at some point and setup a DLL system to understand those problem better - I'm happy using Edit & Continue or Recode which doesn't requires DLL nor kill instances). |
I think those changes would help - it'd avoid having |
In spite of being a little odd, It wouldn’t hurt to implement your suggestion with an explicit comment to describe it. So I’m going to do that in the meanwhile as it is an easy change.
|
- YOU NOW NEED TO CALL ImGui::CreateContext() AT THE BEGINNING OF YOUR APP, AND CALL ImGui::DestroyContext() AT THE END. - removed Shutdown() function, as DestroyContext() serve this purpose. - you may pass a ImFontAtlas* pointer to CreateContext() to share a font atlas between contexts. Otherwhise CreateContext() will create its own font atlas instance. - removed allocator parameters from CreateContext(), they are now setup with SetAllocatorFunctions(), and shared by all contexts. - removed the default global context and font atlas instance, which were confusing for users of DLL reloading and users of multiple contexts (#1565, #586, #992, #1007, #1558)
@aiekick the changes described in #1565 should fix everything described in this issue. There's no default static/global context in imgui.cpp, only a pointer and you need to call CreateContext() to allocate a context. If you have |
Hello,
i have a InputText Field, if i copy paste some data from the clipboard. when i call the app, after the ImGui::Shutdown(); the app crash here in imgui.cpp
i use your imgui_impl_sdl of example directory.
if i write something, there is no problem, but when i do ctrl+v, it crash (only when i close the app).
I dont know why this code is called after the ImGui:Shutdown(), and the callgraph of vs2015 on win7 give that
The text was updated successfully, but these errors were encountered: