-
-
Notifications
You must be signed in to change notification settings - Fork 10.5k
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
DestroyContext should set GImDefaultContext #1007
Comments
Both very good points, looking into it. |
|
In my glfwgl3 implementation with contexts I get default context for being able to set it before destroying mine to avoid crashing (that's why i need it) I think it would be simpler if DestroyContext does this. |
I don't understand, what exactly is crashing?
I thought you meant that using ImGui:: functions after destroying current context crashed, which is normal. If it's anything else please clarify :)
|
I am doing Shutdown afterwards, perhaps Shutdown is trying to access context. |
Without looking closely at the issue, but basing on my experience. Crashing could be caused by GImDefaultFontAtlas which if initialized require valid context to be present during destruction. Otherwise ImVector it contains cannot access (valid) free function (see: ImGui::MemFree). Bottom line is, if you destroy default context but keep using second one, when closing application crash is guaranteed. To avoid such issues I modified my copy of ImGui to not create default context nor default atlas at all. |
I prefer not to modify ImGui and only modify the implementation |
Note that you can #define GImGui in imconfig.h and among other things it will disable the default context. I'm however interested in fixing that mess with the allocators. I think we should move the allocators outside of the context, into globals GImGuiMalloc GImGuifFree? |
I dont mind having a default context. Just want to do destroycontext followed by shutdown. Solutions can be fixing allocators or just changing destroycontext to set default context. |
Ability to override default malloc/free pair in imconfig.h looks like a good idea. This will however not solve problem with finalisation order. GDefaultFontAtlas still has a ImVector and will be destructed after main(). By this time user allocator may be long gone. I added options to disable creation of default context and global font atlas. I can prepare a PR with those changes if you like. |
It is the same happenning in #992 |
do you have a fix for now ? please |
@aiekick you shouldn't be reliant on a fix since you can always set the context yourself afterward? |
i say that because, i failed to fix by the solution upper. but ok i search more. no problem. i understand :) |
ok i just gain understanding of the principle of the imgui context. its ok, it work. thanks :) |
@aiekick in #1007 (comment) |
- 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)
@sonoro1234 The issues discussed here should now be clarified and fixed by the changes discussed in #1565. Context creation are now explicit, and have a parameter to pass in a font atlas created by the user. |
Hi,
actually DestroyContext is:
this makes imgui crash unless I set GImDefaultContext as the current context from the implementation.
perhaps it would be better to have:
or to avoid some extrange behaviour of free_fn changing ctx value
The text was updated successfully, but these errors were encountered: