-
-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
crash while building a font atlas from merged fonts #8081
Comments
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. |
Hmmm, // 8. Copy rasterized font characters back into the main texture
// 9. Setup ImFont and glyphs for runtime
bool tex_use_colors = false;
for (int src_i = 0; src_i < src_tmp_array.Size; src_i++)
{
ImFontBuildSrcDataFT& src_tmp = src_tmp_array[src_i];
if (src_tmp.GlyphsCount == 0)
continue; Can you try to move this block
AFTER the |
…onts and the first font in a merged set has no loaded glyph. (#8081)
I went ahead and pushed this 3b68392 because it seems like the only possible cause for this. |
My first attempt to confirm the fix was a failure; it crashed in both cases. I will try again. |
It is fixed! Thank you! |
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.The text was updated successfully, but these errors were encountered: