I am trying to use FreeType library to load a font atlas on a texture.
For some odd reason when I run the software I get different results with FT_Load_Char
each time.
What the software does is:
It initializes OpenGL.
Initializes FT_Library
with:
FT_Library* ft = (FT_Library*) malloc(sizeof(FT_Library));
FT_Init_FreeType(ft);
Initialize FT_Face
with:
FT_Face* face = (FT_Face*) malloc(sizeof(FT_Face));
FT_New_Memory_Face(*ft, bufferPtr, lengthOfArray, 0, face);
(Where bufferPtr points to a valid byte buffer containing font data)
Set fontSize with values width = 0, height = 22:
FT_Set_Pixel_Sizes(*face, width, height);
In a loop load each character 10, 32-255 with:
FT_Load_Char(*face, character, flags) //flags = FT_LOAD_RENDER
Then in the same loop after loading the character get glyph data and read it:
FT_GlyphSlot glyph = (*face)->glyph;
glyph->bitmap.width, glyph->bitmap.rows,
glyph->bitmap_left, glyph->bitmap_top,
glyph->advance.x
Here's a sample result of 20 consecutive software runs. "All" means FT_Load_Char
throwing error with every single character 10, 32-255:
Crash
EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00007ffbcc5b4fd0, pid=14080, tid=0x0000000000002684
Stack: [0x0000000002b80000,0x0000000002c80000], sp=0x0000000002c7f170, free space=1020k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C [freetype.dll+0x64fd0]
C [freetype.dll+0x5aad3]
C [freetype.dll+0xfed6]
C [FontAtlasGenerator.dll+0x188c]
C 0x0000000002d98c67
No errors
What I think are possible causes for the issue: Synchronization? I use FreeType library with Java JNI which might cause some issues? Should I load the fonts in another thread? Memory leak that causes such behavior? (I have 32Gb RAM, RTX2080 TI GPU - loading 255 glyphs to memory with fontSize 22 shouldn't be an issue?) Wrong version of FreeType library? (OS: Windows 10)
User contributions licensed under CC BY-SA 3.0