freetype
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [ft] FT_Get_Char_Index crashing randomly (luajit and ffi)


From: Elias Hogstvedt
Subject: Re: [ft] FT_Get_Char_Index crashing randomly (luajit and ffi)
Date: Tue, 17 Sep 2013 00:56:21 +0200

I've figured out what the problem was already. I also forgot to mention I was using absolute latest version of freetype from git, but that doesn't matter.
 
The problem was that I was loading the face from memory. The data (binary font data) I passed to that function was getting garbage collected due to it not being referenced anywhere. (embarrassing!)



On Tue, Sep 17, 2013 at 12:31 AM, Elias Hogstvedt <address@hidden> wrote:
I've been learning how to use freetype with opengl but I've ran into this problem I can't find any information about on google. I'm new to opengl as well so excuse the newbieness!

It's called from luajit using its ffi interface but I've compiled debug dlls so I can debug with visual studio. It tells me it crashes in the function "static FT_UInt tt_cmap4_char_map_binary" here:
___________________________________________________________________
....
    1104   p = cmap->data + 6;
 > 1105   num_segs2 = FT_PAD_FLOOR( TT_PEEK_USHORT( p ), 2 );
......
___________________________________________________________________

Where visual studio says p is a bad pointer. ( Unhandled exception at 0x0f814c0c (libfreetype_d.dll) in luajit.exe: 0xC0000005: Access violation reading location 0x7bcf581a. )

I've tried compiling both mt and st release but it happens with both.

The font I'm using is unifont.ttf. I've also tried other fonts but it's the same.

It's hard to show related code, so instead I made something that logs all freetype calls instead:
____________________________________________________
0 = FT_Init_FreeType(cdata<struct FT_LibraryRec_ *[1]>: 0x02fc0058)
0 = FT_New_Memory_Face(cdata<struct FT_LibraryRec_ *>: 0x041bb858, *unifont.ttf binary content*, 13552768, 0, cdata<struct FT_FaceRec_ *[1]>: 0x05d3d440)
0 = FT_Set_Char_Size(cdata<struct FT_FaceRec_ *>: 0x041c64c0, 0, 1008, 72, 72)
___________________________________________________________________

Then it crashes calling "FT_Get_Char_Index(cdata<struct FT_FaceRec_ *>: 0x041c64c0, 230)"

A successful run looks like this:
___________________________________________________________________
0 = FT_Init_FreeType(cdata<struct FT_LibraryRec_ *[1]>: 0x03118450)
0 = FT_New_Memory_Face(cdata<struct FT_LibraryRec_ *>: 0x03bfe0f0, *unifont.ttf binary content*, 13552768, 0, cdata<struct FT_FaceRec_ *[1]>: 0x0309de80)
0 = FT_Set_Char_Size(cdata<struct FT_FaceRec_ *>: 0x03c0a1a8, 0, 1008, 72, 72)
232 = FT_Get_Char_Index(cdata<struct FT_FaceRec_ *>: 0x03c0a1a8, 230)
0 = FT_Load_Glyph(cdata<struct FT_FaceRec_ *>: 0x03c0a1a8, 232, 0)
0 = FT_Render_Glyph(cdata<struct FT_GlyphSlotRec_ *>: 0x00bec2e8, 0)
250 = FT_Get_Char_Index(cdata<struct FT_FaceRec_ *>: 0x03c0a1a8, 248)
0 = FT_Load_Glyph(cdata<struct FT_FaceRec_ *>: 0x03c0a1a8, 250, 0)
0 = FT_Render_Glyph(cdata<struct FT_GlyphSlotRec_ *>: 0x00bec2e8, 0)
231 = FT_Get_Char_Index(cdata<struct FT_FaceRec_ *>: 0x03c0a1a8, 229)
0 = FT_Load_Glyph(cdata<struct FT_FaceRec_ *>: 0x03c0a1a8, 231, 0)
0 = FT_Render_Glyph(cdata<struct FT_GlyphSlotRec_ *>: 0x00bec2e8, 0)
127 = FT_Get_Char_Index(cdata<struct FT_FaceRec_ *>: 0x03c0a1a8, 124)
0 = FT_Load_Glyph(cdata<struct FT_FaceRec_ *>: 0x03c0a1a8, 127, 0)
0 = FT_Render_Glyph(cdata<struct FT_GlyphSlotRec_ *>: 0x00bec2e8, 0)
114 = FT_Get_Char_Index(cdata<struct FT_FaceRec_ *>: 0x03c0a1a8, 111)
0 = FT_Load_Glyph(cdata<struct FT_FaceRec_ *>: 0x03c0a1a8, 114, 0)
0 = FT_Render_Glyph(cdata<struct FT_GlyphSlotRec_ *>: 0x00bec2e8, 0)
115 = FT_Get_Char_Index(cdata<struct FT_FaceRec_ *>: 0x03c0a1a8, 112)
0 = FT_Load_Glyph(cdata<struct FT_FaceRec_ *>: 0x03c0a1a8, 115, 0)
0 = FT_Render_Glyph(cdata<struct FT_GlyphSlotRec_ *>: 0x00bec2e8, 0)
118 = FT_Get_Char_Index(cdata<struct FT_FaceRec_ *>: 0x03c0a1a8, 115)
0 = FT_Load_Glyph(cdata<struct FT_FaceRec_ *>: 0x03c0a1a8, 118, 0)
0 = FT_Render_Glyph(cdata<struct FT_GlyphSlotRec_ *>: 0x00bec2e8, 0)
26024 = FT_Get_Char_Index(cdata<struct FT_FaceRec_ *>: 0x03c0a1a8, 27721)
0 = FT_Load_Glyph(cdata<struct FT_FaceRec_ *>: 0x03c0a1a8, 26024, 0)
0 = FT_Render_Glyph(cdata<struct FT_GlyphSlotRec_ *>: 0x00bec2e8, 0)
34124 = FT_Get_Char_Index(cdata<struct FT_FaceRec_ *>: 0x03c0a1a8, 35821)
0 = FT_Load_Glyph(cdata<struct FT_FaceRec_ *>: 0x03c0a1a8, 34124, 0)
0 = FT_Render_Glyph(cdata<struct FT_GlyphSlotRec_ *>: 0x00bec2e8, 0)
50 = FT_Get_Char_Index(cdata<struct FT_FaceRec_ *>: 0x03c0a1a8, 47)
0 = FT_Load_Glyph(cdata<struct FT_FaceRec_ *>: 0x03c0a1a8, 50, 0)
0 = FT_Render_Glyph(cdata<struct FT_GlyphSlotRec_ *>: 0x00bec2e8, 0)
26753 = FT_Get_Char_Index(cdata<struct FT_FaceRec_ *>: 0x03c0a1a8, 28450)
0 = FT_Load_Glyph(cdata<struct FT_FaceRec_ *>: 0x03c0a1a8, 26753, 0)
0 = FT_Render_Glyph(cdata<struct FT_GlyphSlotRec_ *>: 0x00bec2e8, 0)
33789 = FT_Get_Char_Index(cdata<struct FT_FaceRec_ *>: 0x03c0a1a8, 35486)
0 = FT_Load_Glyph(cdata<struct FT_FaceRec_ *>: 0x03c0a1a8, 33789, 0)
0 = FT_Render_Glyph(cdata<struct FT_GlyphSlotRec_ *>: 0x00bec2e8, 0)
___________________________________________________________________

The text I'm getting glyph information from is "æøå|ops汉语/漢語" and it renders successfully in opengl when doesn't crash.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]