From 99712515740102ad6ea4db96300ed319453fa1fc Mon Sep 17 00:00:00 2001 From: ocornut Date: Wed, 10 Dec 2025 21:42:07 +0100 Subject: [PATCH] Fonts: amend/comment on FontDataOwnedByAtlas=false fix being a breaking change. (#9086, #8465) --- docs/CHANGELOG.txt | 17 ++++++++++++----- docs/FONTS.md | 1 + imgui.cpp | 6 ++++++ imgui.h | 2 +- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 824e05990..faf1ebb2c 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -41,14 +41,21 @@ HOW TO UPDATE? Breaking Changes: +- Fonts: Fixed handling of `ImFontConfig::FontDataOwnedByAtlas = false` which + did erroneously make a copy of the font data, essentially defeating the purpose + of this flag and wasting memory (undetected since July 2015 and now spotted + by @TellowKrinkle, this is perhaps the oldest bug in Dear ImGui history, + albeit for a rarely used feature!) (#9086, #8465) + HOWEVER, fixing this bug is likely to surface bugs in user/app code: + - Prior to 1.92, font data only needs to be available during the atlas->AddFontXXX() call. + - Since 1.92, font data needs to available until atlas->RemoveFont(), or more typically + until a shutdown of the owning context or font atlas. + - The fact that handling of `FontDataOwnedByAtlas = false` was broken + bypassed the issue altogether. + Other Changes: - Fonts: - - Fixed handling of `ImFontConfig::FontDataOwnedByAtlas = false` which - did erroneously make a copy of the font data, essentially defeating the purpose - of this flag and wasting memory. - Undetected since July 2015 and now spotted by @TellowKrinkle, this is perhaps - the oldest bug in Dear ImGui history (albeit for a rarely used feature)! (#9086) - Fixed an issue related to EllipsisChar handling, while changing font loader or font loader flags dynamically in Style->Fonts menus. - Textures: diff --git a/docs/FONTS.md b/docs/FONTS.md index 072ca9762..1a466be8d 100644 --- a/docs/FONTS.md +++ b/docs/FONTS.md @@ -228,6 +228,7 @@ ImFontConfig font_cfg; font_cfg.FontDataOwnedByAtlas = false; ImFont* font = io.Fonts->AddFontFromMemoryTTF(data, data_size, size_pixels, &font_cfg); ``` +IMPORTANT: Since 1.92, when using `FontDataOwnedByAtlas = false`, font data needs to available until `atlas->RemoveFont()`, or more typically until a shutdown of the owning context or font atlas. It was not immediately noticeable in 1.92.0 due to a bug in handling `FontDataOwnedByAtlas = false`, which was fixed in 1.92.6. ##### [Return to Index](#index) diff --git a/imgui.cpp b/imgui.cpp index a977c773c..52b4f0f66 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -394,6 +394,12 @@ IMPLEMENTING SUPPORT for ImGuiBackendFlags_RendererHasTextures: When you are not sure about an old symbol or function name, try using the Search/Find function of your IDE to look for comments or references in all imgui files. You can read releases logs https://github.com/ocornut/imgui/releases for more details. + - 2025/11/24 (1.92.6) - Fonts: Fixed handling of `ImFontConfig::FontDataOwnedByAtlas = false` which did erroneously make a copy of the font data, essentially defeating the purpose of this flag and wasting memory. + (trivia: undetected since July 2015, this is perhaps the oldest bug in Dear ImGui history, albeit for a rarely used feature, see #9086) + HOWEVER, fixing this bug is likely to surface bugs in user code using `FontDataOwnedByAtlas = false`. + - Prior to 1.92, font data only needed to be available during the atlas->AddFontXXX() call. + - Since 1.92, font data needs to available until atlas->RemoveFont(), or more typically until a shutdown of the owning context or font atlas. + - The fact that handling of `FontDataOwnedByAtlas = false` was broken bypassed the issue altogether. - 2025/11/06 (1.92.5) - BeginChild: commented out some legacy names which were obsoleted in 1.90.0 (Nov 2023), 1.90.9 (July 2024), 1.91.1 (August 2024): - ImGuiChildFlags_Border --> ImGuiChildFlags_Borders - ImGuiWindowFlags_NavFlattened --> ImGuiChildFlags_NavFlattened (moved to ImGuiChildFlags). BeginChild(name, size, 0, ImGuiWindowFlags_NavFlattened) --> BeginChild(name, size, ImGuiChildFlags_NavFlattened, 0) diff --git a/imgui.h b/imgui.h index 7f8b6f3ac..09fef133f 100644 --- a/imgui.h +++ b/imgui.h @@ -3521,7 +3521,7 @@ struct ImFontConfig char Name[40]; // // Name (strictly to ease debugging, hence limited size buffer) void* FontData; // // TTF/OTF data int FontDataSize; // // TTF/OTF data size - bool FontDataOwnedByAtlas; // true // TTF/OTF data ownership taken by the owner ImFontAtlas (will delete memory itself). + bool FontDataOwnedByAtlas; // true // TTF/OTF data ownership taken by the owner ImFontAtlas (will delete memory itself). SINCE 1.92, THE DATA NEEDS TO PERSIST FOR WHOLE DURATION OF ATLAS. // Options bool MergeMode; // false // Merge into previous ImFont, so you can combine multiple inputs font into one ImFont (e.g. ASCII font + icons + Japanese glyphs). You may want to use GlyphOffset.y when merge font of different heights.