You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Calling DrawTextCodepoint (and other functions working on fonts, I assume) with an invalid Font structure causes SIGSEGV, presumably due to the following line in the GetGlyphIndex function:
if ((index == 0) && (font.glyphs[0].value != codepoint)) index = fallbackIndex;
Causing this SIGSEGV is easy, as LoadFont doesn't indicate that it failed with an error, and IsFontValid is not used in the examples after loading fonts.
Possible solutions:
DrawTextCodepoint and similar functions call IsFontValid instead of assuming that font is valid.
DrawTextCodepoint and similar functions check font.glyphCount>0 instead of assuming that font is valid.
A boolean flag called isValid is added to the Font structure, indicating that the font is valid, and functions like DrawTextCodepoint check it each time they're called.
LoadFont returns an int which indicates that loading the font failed.
IsFontValid is shown in all examples.
Environment
Linux 6.11
Issue Screenshot
Code Example
intmain(void) {
Fontfont=LoadFont("font.ttf"); // a non-existent fontprintf("Glyph count = %d\n", font.glyphCount); // 0InitWindow(800, 600, "title");
while (!WindowShouldClose()) {
BeginDrawing();
DrawTextCodepoint(
font,
'a',
(Vector2){100,100},
100,
GREEN
);
EndDrawing();
}
}
The text was updated successfully, but these errors were encountered:
raysan5
changed the title
[rtext] DrawTextCodepoint doesn't check if font is valid, which causes SIGSEGV
[rtext] DrawTextCodepoint() doesn't check if font is valid, which causes SIGSEGV
Nov 22, 2024
A simple check like if (font.glyphCount == 0) return 0; would also work instead of a call to IsFontValid(). I think that wouldn't incur a significant delay. Honestly, a call to IsFontValid() is also not that wasteful imo, as it only does a few if checks. Compared to the rest of GetGlyphIndex() it's no big deal. We have to measure the added delays before drawing the conclusion that it's really wasteful...
In my opinion, what's important here than performance is to prevent a possible SIGSEGV, which I demonstrated that it happens.
Issue description
Calling DrawTextCodepoint (and other functions working on fonts, I assume) with an invalid Font structure causes SIGSEGV, presumably due to the following line in the GetGlyphIndex function:
if ((index == 0) && (font.glyphs[0].value != codepoint)) index = fallbackIndex;
Causing this SIGSEGV is easy, as LoadFont doesn't indicate that it failed with an error, and IsFontValid is not used in the examples after loading fonts.
Possible solutions:
Environment
Linux 6.11
Issue Screenshot
Code Example
The text was updated successfully, but these errors were encountered: