1
0
Fork 0
mirror of https://github.com/ocornut/imgui.git synced 2026-01-11 00:04:24 +00:00

Fonts: fixed memory leaks, shutting down font loader, and on AddFont() failure in FreeType backend.

This commit is contained in:
ocornut 2025-03-11 11:46:18 +01:00 committed by ocornut
parent 52a6863771
commit 144f444217
3 changed files with 13 additions and 8 deletions

View file

@ -3034,7 +3034,10 @@ ImFont* ImFontAtlas::AddFont(const ImFontConfig* font_cfg)
new_font_cfg.GlyphExcludeRanges = (ImWchar*)ImMemdup(font_cfg->GlyphExcludeRanges, sizeof(font_cfg->GlyphExcludeRanges[0]) * (size + 1));
}
if (font_cfg->FontLoader != NULL)
{
IM_ASSERT(font_cfg->FontLoader->FontBakedLoadGlyph != NULL);
IM_ASSERT(font_cfg->FontLoader->LoaderInit == NULL && font_cfg->FontLoader->LoaderShutdown == NULL); // FIXME-NEWATLAS: Unsupported yet.
}
IM_ASSERT(font_cfg->FontLoaderData == NULL);
// Round font size
@ -3369,11 +3372,6 @@ void ImFontAtlasBuildSetupFontLoader(ImFontAtlas* atlas, const ImFontLoader* fon
ImVec2i new_tex_size = ImFontAtlasBuildGetTextureSizeEstimate(atlas);
ImFontAtlasBuildDestroy(atlas);
if (atlas->FontLoader && atlas->FontLoader->LoaderShutdown)
{
atlas->FontLoader->LoaderShutdown(atlas);
IM_ASSERT(atlas->FontLoaderData == NULL);
}
atlas->FontLoader = font_loader;
atlas->FontLoaderName = font_loader ? font_loader->Name : "NULL";
if (atlas->FontLoader && atlas->FontLoader->LoaderInit)
@ -4187,7 +4185,11 @@ void ImFontAtlasBuildDestroy(ImFontAtlas* atlas)
if (loader && loader->FontSrcDestroy != NULL)
loader->FontSrcDestroy(atlas, &font_cfg);
}
if (atlas->FontLoader && atlas->FontLoader->LoaderShutdown)
{
atlas->FontLoader->LoaderShutdown(atlas);
IM_ASSERT(atlas->FontLoaderData == NULL);
}
IM_DELETE(atlas->Builder);
atlas->Builder = NULL;
}