lost_bits1110
lost_bits1110

Reputation: 2420

FreeType FT_New_Memory_Face crashes

I have loaded an "arial.ttf" file (taken from my /Windows/Fonts folder) into memory, however passing this into FT_New_Memory_Face crashes (somewhere in FT_Open_Face). I am not able to debug this, any clues as to what I might be doing wrong?

unsigned char *fontBuffer = LoadFile("arial.ttf");
zip_uint64_t fSize = GetFileSize("arial.ttf");
FT_Library  library;   /* handle to library     */
FT_Face     face; 
int error = FT_Init_FreeType( &library );
if( error != 0 )
    printf("FT_Init_FreeType failed");

error = FT_New_Memory_Face( library,
                            (FT_Byte*)fontBuffer,
                            fSize,                  
                            0,                      
                            &face );

Upvotes: 2

Views: 3493

Answers (2)

I searched for the answer for 1 day. The problem was in note section. https://www.freetype.org/freetype2/docs/reference/ft2-base_interface.html#FT_New_Memory_Face You must not deallocate the memory before calling FT_Done_Face. FreeType don't copying buffer and uses pointer that you send to FT_New_Memory_Face

Upvotes: 4

lost_bits1110
lost_bits1110

Reputation: 2420

It turns out the problem was on my end, particularly, the LoadFile method was returning memory from the stack, rather than the heap. The library works fine. Thanks!

Upvotes: 6

Related Questions