From d2468507875486faa03bbf95f56171047b65b6a7 Mon Sep 17 00:00:00 2001 From: ocornut Date: Thu, 13 Nov 2025 15:42:19 +0100 Subject: [PATCH] Fonts: added comment about the classic AddFontFromMemoryTTF() issue. (#9067, #6916, #6781, #5330, #4307, #2042, #2029, #1734, #1259, #220) --- imgui_draw.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 54d72f410..21ae9e258 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -3633,6 +3633,11 @@ void ImFontAtlasFontSourceAddToFont(ImFontAtlas* atlas, ImFont* font, ImFontConf void ImFontAtlasFontDestroySourceData(ImFontAtlas* atlas, ImFontConfig* src) { IM_UNUSED(atlas); + // IF YOU GET A CRASH IN THE IM_FREE() CALL HERE AND USED AddFontFromMemoryTTF(): + // - DUE TO LEGACY REASON AddFontFromMemoryTTF() TRANSFERS MEMORY OWNERSHIP BY DEFAULT. + // - IT WILL THEREFORE CRASH WHEN PASSED DATA WHICH MAY NOT BE FREEED BY IMGUI. + // - USE `ImFontConfig font_cfg; font_cfg.FontDataOwnedByAtlas = false; io.Fonts->AddFontFromMemoryTTF(....., &cfg);` to disable passing ownership/ + // WE WILL ADDRESS THIS IN A FUTURE REWORK OF THE API. if (src->FontDataOwnedByAtlas) IM_FREE(src->FontData); src->FontData = NULL;