Freetype FT_Request_Size() crashes on Android

杀马特。学长 韩版系。学妹 提交于 2019-12-23 03:13:00

问题


I've compiled freetype 2.4.2 on android and any time I try to use FT_Set_Char_Size() it will crash in the ftobjs.c file in the FT_Request_Size() function at this line

error = clazz->request_size( face->size, req );    //line 2832

My code works perfectly fine on Windows, Linux, Mac, IPhone and IPad. But here is the deal. I was having the exact same issue, same crash at the same spot on Windows (vc++) until I compiled freetype with /Za "Disable Language Extensions".

So I'm pretty sure it's how freetype is being compiled on Android that is causing the crash. I've looked up how to Disable Language Extensions on android with no avail.

here is my Android.mk file for freetype

LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)

LOCAL_C_INCLUDES += \
    $(LOCAL_PATH)/builds \
    $(LOCAL_PATH)/include

LOCAL_SRC_FILES:= \
    src/base/ftbbox.c \
    src/base/ftbitmap.c \
    src/base/ftglyph.c \
    src/base/ftstroke.c \
    src/base/ftxf86.c \
    src/base/ftbase.c \
    src/base/ftsystem.c \
    src/base/ftinit.c \
    src/base/ftgasp.c \
    src/raster/raster.c \
    src/sfnt/sfnt.c \
    src/smooth/smooth.c \
    src/autofit/autofit.c \
    src/truetype/truetype.c \
    src/cff/cff.c \
    src/psnames/psnames.c \
    src/pshinter/pshinter.c \
    src/type1/type1.c \
    src/cid/type1cid.c \
    src/pfr/pfr.c \
    src/type42/type42.c \
    src/winfonts/winfnt.c \
    src/pcf/pcf.c \
    src/psaux/psaux.c \
    src/bdf/bdf.c \
    src/gzip/ftgzip.c \
    src/lzw/ftlzw.c

LOCAL_CFLAGS += -DFT2_BUILD_LIBRARY
LOCAL_MODULE := freetype
LOCAL_LDLIBS := -ldl -llog

include $(BUILD_STATIC_LIBRARY)

My full project can be found here

    http://digitalknob.googlecode.com

It compiles fine and I get no errors. Just the crash when I use FT_Set_Char_Size(). Driving me crazy for a few days now :P Any help is so greatly appreciated.


回答1:


Here is the answer. It turns out the problem the whole time was loading the font file out of the .apk file since it is technically compressed. With SDL, We use SDL_RWops to load the font file within the assets folder of the .apk file. We load the font file into OpenGLES using ftgles. Full example can be found at www.digitalknob.com

SDL_RWops *file = SDL_RWFromFile(filename, "rb"); 

unsigned long fileLen; 
SDL_RWseek(file,0,SEEK_END); 
fileLen=SDL_RWtell(file); 
SDL_RWseek(file,0,SEEK_SET); 

//Allocate memory 
buffer=(unsigned char *)malloc(fileLen+1); 
if (!buffer){ 
   printf("Memory error!\n"); 
   SDL_RWclose(file); 
   return; 
} 

//Read file contents into buffer 
SDL_RWread(file, buffer, fileLen, 1); 
SDL_RWclose(file); 

texture_font = new FTGLTextureFont(buffer, fileLen); 
texture_font->FaceSize(18); 

//don't forget to free your buffer later.
//free(buffer);

If your not using SDL, you'll need zlib or something to access the font file.



来源:https://stackoverflow.com/questions/10875343/freetype-ft-request-size-crashes-on-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!