Open db48x opened 1 week ago
I updated the example code to make it easier to run.
Also, I attempted to fix the crash. The result is a small patch:
diff --git a/imgui_draw.cpp b/imgui_draw.cpp
index bf1da15b..56f64072 100644
--- a/imgui_draw.cpp
+++ b/imgui_draw.cpp
@@ -2607,13 +2607,13 @@ void ImFontAtlasBuildSetupFont(ImFontAtlas* atlas, ImFont* font, ImFontConfig* f
if (!font_config->MergeMode)
{
font->ClearOutputData();
- font->FontSize = font_config->SizePixels;
font->ConfigData = font_config;
font->ConfigDataCount = 0;
- font->ContainerAtlas = atlas;
- font->Ascent = ascent;
- font->Descent = descent;
}
+ font->ContainerAtlas = atlas;
+ font->FontSize = font_config->SizePixels;
+ font->Ascent = ascent;
+ font->Descent = descent;
font->ConfigDataCount++;
}
This avoids the crash, but when in the English locale it loses the names of the constituent fonts. I haven't dug deeper into how that information is tracked.
Version/Branch of Dear ImGui:
Version 1.86, Branch: master
Back-ends:
SDL
Compiler, OS:
Linux + clang 18.1.8
Full config/build information:
Details:
For some reason, ImGui is crashing while building the font atlas. I build a font range based on the user’s locale setting, then I loop through a list of fonts (configurable by the user). For the first font in the list I set
MergeMode
tofalse
. For every other font in the list I setMergeMode
totrue
so that these fonts will be used as a fallback in case a glyph is not found in a font earlier in the list. I do this first for a variable‐width font, then again for a monospaced font.The crash happens when the locale is set to
en
and the font list contains a Japanese font. (Other combinations crash as well; the key seems to be that the Japanese font has no glyphs needed by the chosen locale). Notably it does not crash if the locale is set toja
, or if the Japanese font is removed from the font list.Here is what the font atlas looks like when the locale is
ja
and the Japanese font is included in the list:You can see that the atlas is still a fairly reasonable size and everything is working fine.
Here’s what the stack looks like:
And here’s what’s in my
load_fonts
function:For each language I have pulled a set of characters from the CLDR database
Screenshots/Video:
No response
Minimal, Complete and Verifiable Example code:
First, define these functions:
Check the args:
Then, call them from
main
just after the renderer is initialized:./example_sdl_sdlrenderer "en"
crashes,./example_sdl_sdlrenderer "ja"
does not.