Closed techie-guy closed 6 months ago
Looking at the code, I think the problem is that there's a special case here for ImVector
because ImFontGlyphRangesBuilder_BuildRanges()
has to be able to resize the vector it is using, resulting in memory allocated internally within ImGui (potentially using a different heap from the user code and thus causing chaos when the vector is deallocated).
There are some more notes in the Readme.md
file about this (see the section on "Constructors/destructors"), but I think that the code above can probably be fixed by adding the three commented lines here:
ImGui_CreateContext(NULL);
ImGuiIO* io = ImGui_GetIO();
ImVector_ImWchar ranges;
ImVector_Construct(&ranges); // Construct the vector
ImFontGlyphRangesBuilder builder;
memset(&builder, 0, sizeof(builder)); // Probably not related to the current issue but recommended if you don't have compiler flags set to guarantee zero-initialisation
ImFontGlyphRangesBuilder_Clear(&builder);
ImFontGlyphRangesBuilder_AddRanges(&builder, ImFontAtlas_GetGlyphRangesDefault(io->Fonts));
ImFontGlyphRangesBuilder_AddText(&builder, "", NULL);
ImFontGlyphRangesBuilder_BuildRanges(&builder, &ranges);
ImFontAtlas_AddFontFromFileTTF(io->Fonts, "assets/fonts/font.ttf", 45, NULL, ranges.Data);
ImFontAtlas_Build(io->Fonts);
ImVector_Destruct(&ranges); // Free the vector using ImGui's heap functions
Hopefully that helps - if it doesn't then let me know and I'll dig a bit deeper!
It worked, Thanks!
I am trying to load in a custom font(Nerd Font)
On Running the app, I get this:
GDB Backtrace:
Am I doing anything incorrectly?