-
-
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
GImDefaultFontAtlas causes problems with custom allocator #396
Comments
What is the problem exactly? The constructor for GImDefaultFontAtlas shouldn't allocate anything. The only requirement is that you set the memory functions before calling NewFrame or any of the font functions such as AddFont or GetTexData* |
The problem is that static destructor is clearing it, and data contained is allocated with custom allocator that is gone by the time static destructors run. ImGui::Shutdown() should clean it instead. If you need repro case just run 20-nanovg from bgfx and it will crash on shutdown. |
OK so the problem is in Shutdown(). Will look into that. |
I couldn't find the problem. Unless you are manipulating and changing the g.IO.Fonts pointer (which should point to GImDefaultFontAtlas), Shutdown() clears it and afaik MemFree() is called everywhere there. Which field is causing a problem? Can you confirm that you are doing things in this order?
|
Ok, found it, in this particular case I initialized ImGui because stb TTF is used between ImGui and NanoVG, but I never called ImGui::NewFrame because there is no ImGui. Maybe, adding ImGui::NewFrame into ImGui::Shutdown would be good to prevent this kind of bug? |
I'd rather make it fullproof without calling NewFraame(). Was exactly was misfreed or crashing? (of the two bug reports i keep not knowing what it is precisely :) |
It was freed after ImGui::Shutdown. I intentionally NULL allocator in my code to catch this kind of bugs. |
I'll go and update/build bgfx tonight to try to get a repro. Nobody wants to tell me WHAT is freed, WHICH FIELD(S) ? it sounds like a conspiracy that I can't get an answer. |
Here is info:
|
Alright :) it all makes sense now. If you don't call NewFrame(), ImGui is marked as not initialized and Shutdown() doesn't clear the FontAtlas either. I'll fix that! |
Thanks for sorry for taking so long to figure that out! |
Problem with this code:
https://github.com/ocornut/imgui/blob/master/imgui.cpp#L623
Is that allocations might happen with different allocators. It uses default allocator before custom allocator is set and afterwards it uses custom allocator. On shutdown even if default allocator is set there still might be lingering block allocated with custom allocator.
The text was updated successfully, but these errors were encountered: