Skip to content
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

ImFontAtlasBuildWithStbTrueType assertion with Gcc 13+ #7856

Closed
smallstepforman opened this issue Aug 3, 2024 · 6 comments
Closed

ImFontAtlasBuildWithStbTrueType assertion with Gcc 13+ #7856

smallstepforman opened this issue Aug 3, 2024 · 6 comments

Comments

@smallstepforman
Copy link

Version/Branch of Dear ImGui:

v1.91.1

Back-ends:

OpenGL / glfw3

Compiler, OS:

gcc 13.2 and higher

Full config/build information:

No response

Details:

With older Gcc compilers (11, 12) and with VS 2022, I have working code which appends a range of glyphs to StbTruetype. Using gcc compiler 13 and 14, I get an assertion in imgui_draw.cpp:2819 bool ImFontAtlasBuildWithStbTruetype(ImFontAtlas *) Assertion 'src_range[0] <= src_range[1]' failed.

Screenshots/Video:

No response

Minimal, Complete and Verifiable Example code:

static const ImWchar kAdditionalUnicodeChars[] =
	{
		0x00a1/*¡*/, 0x00a2/*¢*/, 0x00a9/*©*/, 0x00ae/*®*/, 0x00b1/*±*/, 0x00bf/*¿*/, 0x00c3/*Ã*/, 0x00c9/*É*/, 0x00cd/*Í*/, 0x00d1/*Ñ*/,
		0x00d3/*Ó*/, 0x00da/*Ú*/, 0x00e1/*á*/, 0x00e9/*é*/, 0x00ed/*í*/, 0x00f1/*ñ*/, 0x00f3/*ó*/, 0x00fa/*ú*/, 0x0e3f/*฿*/, 0x2018/**/,
		0x2019/**/, 0x201b/**/, 0x201c/**/, 0x20ac/**/, 0x20b1/**/, 0x2122/**/,
	};
	fFonts[0] = io.Fonts->AddFontFromFileTTF("../../Resources/ProximaNova-Regular.ttf", 48);
	fFonts[1] = io.Fonts->AddFontFromFileTTF("../../Resources/ProximaNova-Regular.ttf", 32);
	fFonts[2] = io.Fonts->AddFontFromFileTTF("../../Resources/DejaVuSerif.ttf", 28, &config, kAdditionalUnicodeChars);  // Crashes here with Gcc 13/14, but works fine with VS2022 and GCC 11/12.
@smallstepforman
Copy link
Author

Forgot to add the following for config:
ImFontConfig config;
config.MergeMode = true;

@smallstepforman
Copy link
Author

The glyph range is persistent (static const global)

@ocornut
Copy link
Owner

ocornut commented Aug 3, 2024

There’s no end zero terminator in your array so it’s reading undefined memory.

@smallstepforman
Copy link
Author

That works. Thanks ocornut.

@smallstepforman
Copy link
Author

Not a bug. The array was not zero terminated.

@ocornut
Copy link
Owner

ocornut commented Aug 3, 2024

I will amend the comments to suggest that as another possibility of mistake. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants