Fonts: fixed memory leaks, shutting down font loader, and on AddFont() failure in FreeType backend.
This commit is contained in:
@@ -3711,7 +3711,7 @@ struct ImFont
|
|||||||
IMGUI_API ImFontBaked* GetFontBaked(float font_size); // Get or create baked data for given size
|
IMGUI_API ImFontBaked* GetFontBaked(float font_size); // Get or create baked data for given size
|
||||||
IMGUI_API bool IsGlyphInFont(ImWchar c);
|
IMGUI_API bool IsGlyphInFont(ImWchar c);
|
||||||
bool IsLoaded() const { return ContainerAtlas != NULL; }
|
bool IsLoaded() const { return ContainerAtlas != NULL; }
|
||||||
const char* GetDebugName() const { return Sources ? Sources->Name : "<unknown>"; }
|
const char* GetDebugName() const { return Sources ? Sources[0].Name : "<unknown>"; }
|
||||||
|
|
||||||
// [Internal] Don't use!
|
// [Internal] Don't use!
|
||||||
// 'max_width' stops rendering after a certain width (could be turned into a 2d size). FLT_MAX to disable.
|
// 'max_width' stops rendering after a certain width (could be turned into a 2d size). FLT_MAX to disable.
|
||||||
@@ -3720,7 +3720,6 @@ struct ImFont
|
|||||||
IMGUI_API const char* CalcWordWrapPosition(float size, const char* text, const char* text_end, float wrap_width);
|
IMGUI_API const char* CalcWordWrapPosition(float size, const char* text, const char* text_end, float wrap_width);
|
||||||
IMGUI_API void RenderChar(ImDrawList* draw_list, float size, const ImVec2& pos, ImU32 col, ImWchar c, const ImVec4* cpu_fine_clip = NULL);
|
IMGUI_API void RenderChar(ImDrawList* draw_list, float size, const ImVec2& pos, ImU32 col, ImWchar c, const ImVec4* cpu_fine_clip = NULL);
|
||||||
IMGUI_API void RenderText(ImDrawList* draw_list, float size, const ImVec2& pos, ImU32 col, const ImVec4& clip_rect, const char* text_begin, const char* text_end, float wrap_width = 0.0f, bool cpu_fine_clip = false);
|
IMGUI_API void RenderText(ImDrawList* draw_list, float size, const ImVec2& pos, ImU32 col, const ImVec4& clip_rect, const char* text_begin, const char* text_end, float wrap_width = 0.0f, bool cpu_fine_clip = false);
|
||||||
|
|
||||||
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
|
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
|
||||||
inline const char* CalcWordWrapPositionA(float scale, const char* text, const char* text_end, float wrap_width) { return CalcWordWrapPosition(Sources[0].SizePixels * scale, text, text_end, wrap_width); }
|
inline const char* CalcWordWrapPositionA(float scale, const char* text, const char* text_end, float wrap_width) { return CalcWordWrapPosition(Sources[0].SizePixels * scale, text, text_end, wrap_width); }
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+8
-6
@@ -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));
|
new_font_cfg.GlyphExcludeRanges = (ImWchar*)ImMemdup(font_cfg->GlyphExcludeRanges, sizeof(font_cfg->GlyphExcludeRanges[0]) * (size + 1));
|
||||||
}
|
}
|
||||||
if (font_cfg->FontLoader != NULL)
|
if (font_cfg->FontLoader != NULL)
|
||||||
|
{
|
||||||
IM_ASSERT(font_cfg->FontLoader->FontBakedLoadGlyph != 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);
|
IM_ASSERT(font_cfg->FontLoaderData == NULL);
|
||||||
|
|
||||||
// Round font size
|
// Round font size
|
||||||
@@ -3369,11 +3372,6 @@ void ImFontAtlasBuildSetupFontLoader(ImFontAtlas* atlas, const ImFontLoader* fon
|
|||||||
ImVec2i new_tex_size = ImFontAtlasBuildGetTextureSizeEstimate(atlas);
|
ImVec2i new_tex_size = ImFontAtlasBuildGetTextureSizeEstimate(atlas);
|
||||||
ImFontAtlasBuildDestroy(atlas);
|
ImFontAtlasBuildDestroy(atlas);
|
||||||
|
|
||||||
if (atlas->FontLoader && atlas->FontLoader->LoaderShutdown)
|
|
||||||
{
|
|
||||||
atlas->FontLoader->LoaderShutdown(atlas);
|
|
||||||
IM_ASSERT(atlas->FontLoaderData == NULL);
|
|
||||||
}
|
|
||||||
atlas->FontLoader = font_loader;
|
atlas->FontLoader = font_loader;
|
||||||
atlas->FontLoaderName = font_loader ? font_loader->Name : "NULL";
|
atlas->FontLoaderName = font_loader ? font_loader->Name : "NULL";
|
||||||
if (atlas->FontLoader && atlas->FontLoader->LoaderInit)
|
if (atlas->FontLoader && atlas->FontLoader->LoaderInit)
|
||||||
@@ -4187,7 +4185,11 @@ void ImFontAtlasBuildDestroy(ImFontAtlas* atlas)
|
|||||||
if (loader && loader->FontSrcDestroy != NULL)
|
if (loader && loader->FontSrcDestroy != NULL)
|
||||||
loader->FontSrcDestroy(atlas, &font_cfg);
|
loader->FontSrcDestroy(atlas, &font_cfg);
|
||||||
}
|
}
|
||||||
|
if (atlas->FontLoader && atlas->FontLoader->LoaderShutdown)
|
||||||
|
{
|
||||||
|
atlas->FontLoader->LoaderShutdown(atlas);
|
||||||
|
IM_ASSERT(atlas->FontLoaderData == NULL);
|
||||||
|
}
|
||||||
IM_DELETE(atlas->Builder);
|
IM_DELETE(atlas->Builder);
|
||||||
atlas->Builder = NULL;
|
atlas->Builder = NULL;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -416,7 +416,11 @@ bool ImGui_ImplFreeType_FontSrcInit(ImFontAtlas* atlas, ImFontConfig* src)
|
|||||||
src->FontLoaderData = bd_font_data;
|
src->FontLoaderData = bd_font_data;
|
||||||
|
|
||||||
if (!bd_font_data->InitFont(bd->Library, src, atlas->FontBuilderFlags))
|
if (!bd_font_data->InitFont(bd->Library, src, atlas->FontBuilderFlags))
|
||||||
|
{
|
||||||
|
IM_DELETE(bd_font_data);
|
||||||
|
src->FontLoaderData = NULL;
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user