FreeType FT_Load_Char errors

-1

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:

  1. It initializes OpenGL.

  2. Initializes FT_Library with:

    FT_Library* ft = (FT_Library*) malloc(sizeof(FT_Library));
    FT_Init_FreeType(ft);
    
  3. 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)

  1. Set fontSize with values width = 0, height = 22:

    FT_Set_Pixel_Sizes(*face, width, height);
    
  2. In a loop load each character 10, 32-255 with:

    FT_Load_Char(*face, character, flags) //flags = FT_LOAD_RENDER
    
  3. 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:

  1. All: Error code 134
  2. No errors
  3. 210-255: Error code 20
  4. 200-255: Error code 20
  5. No errors
  6. No errors
  7. 205-255: Error code 20
  8. 179-255: Error code 20
  9. 202-255: Error code 20
  10. No errors
  11. No errors
  12. 189-255: Error code 20
  13. 189-255: Error code 20
  14. All: Error code 132
  15. 214-255: Error code 20
  16. No errors
  17. All: Error code 128
  18. 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
    
  19. No errors

  20. All: Error code 133

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)

opengl
freetype
asked on Stack Overflow Jul 28, 2019 by Kim Rautio

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0