HarfBuzz - hb_shape()会导致访问冲突

时间:2014-03-13 19:24:56

标签: c dll sdl freetype harfbuzz

基于此example,我尝试在SDL应用程序中实现字体渲染。调用 hb_shape()时,由于访问冲突,应用程序将暂停。

DLL-download-link(win32):here {harfbuzz-0.9.26-win32.zip}

ErrorMsg(VC2012):ConsoleApplication2.exe中0x6160B7F0(libharfbuzz-0.dll)处的未处理异常:0xC0000005:读取位置0x00000068时发生访问冲突

编辑:为简单起见,我将示例更改为控制台应用程序。
Edit2:现在静态链接,用VC ++的LIB.exe创建.lib文件。

#include <Windows.h>
#include <iostream>
#include <hb.h>
#include <hb-ft.h>

#pragma comment(lib,"lib/x86/freetype253ST.lib") // freetype single-thread
#pragma comment (lib,"libharfbuzz-0.lib") // linked to libharfbuzz.dll, created by LIB.exe

int main()
{
hb_font_t* font = NULL;
hb_buffer_t* buffer = NULL;
FT_Library flib;
FT_Face face;
bool found = false;

const char text[] = {"Write something...."};

if (FT_Init_FreeType(&flib) == 0)
{
    if (FT_New_Face(flib,"arial.ttf",0,&face) == 0)
    {
        for (int i = 0; i < face->num_charmaps; i++)
        { // search for UNICODE 2.0 charmap
            if ((face->charmaps[i]->encoding_id == 3 && face->charmaps[i]->platform_id == 0) ||
                (face->charmaps[i]->encoding_id == 1 && face->charmaps[i]->platform_id == 3) )
            {
                FT_Set_Charmap(face,face->charmaps[i]);
                found = true;
                break;
            }
        }

        if (found && FT_Set_Char_Size(face,0,50*64,72,72) == 0)
        {
            font = hb_ft_font_create(face,NULL);

            buffer = hb_buffer_create();
            if (hb_buffer_allocation_successful(buffer))
            {
                hb_buffer_set_script(buffer,HB_SCRIPT_LATIN);
                hb_buffer_set_language(buffer, hb_language_from_string("en",strlen("en"))); // strlen("en") is awful but good enough here
                hb_buffer_set_direction(buffer,HB_DIRECTION_LTR);

                hb_buffer_add_utf8(buffer,text,strlen(text),0,strlen(text));

                hb_shape(font,buffer,NULL,0);  // Access violation

                std::cout << "There\n";

                hb_buffer_destroy(buffer);
            }
            hb_font_destroy(font);      
        }

        FT_Done_Face(face);
    }

    FT_Done_FreeType(flib);
}


Sleep(3000);

return 0;

}

0 个答案:

没有答案