1

Based on this example, I try to implement font rendering in my SDL application. When calling hb_shape(), the application is halted because of an access-violation.

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

ErrorMsg (VC2012): Unhandled exception at 0x6160B7F0 (libharfbuzz-0.dll)in ConsoleApplication2.exe: 0xC0000005: Access violation while reading at position 0x00000068

EDIT: I changed the example to a console application, for simplicity.
Edit2: Now linking statically, .lib-file created with VC++'s LIB.exe.

#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;

}

BeschBesch
  • 373
  • 2
  • 11
  • Why do you create the font and then destroy it on the next step (`HB_FontDestroy(font);`)? Your access violation is probably due to that, accessing a font that has already been destroyed. – ysalmi Mar 14 '14 at 18:54
  • Oh yes, thank you. I just "hard-coded" the snippet without using Ctrl+C/Ctrl+V, so this early destroy-call is not in the original code. But still the violation error occurs. I keep searching for any NULL-ptrs or bad initialized struct of harf-buzz but everything seems ok... Obviously, everything is alright with hb_buffer_t and hb_font_t because I can use the getter- and setter-functions on them. – BeschBesch Mar 14 '14 at 19:26
  • I tried my luck with the disassembly but did not find anything useful. I halts at the line: 6160B801 8B 00 mov eax,dword ptr [eax]. I am no pro at assembler but a mov on itself (NOP) should not result in an error, leaving to say that whatever was stored to eax is corrupted.. I have found out that calling hb_shape leads to a infinite loop when it comes to select a shapeplan that matches the given input(direction,face, etc.) – BeschBesch Mar 16 '14 at 12:33
  • I don't really know hard-buzz well enough to help further, but I would suggest starting from the example you linked, get it to work and then stripping things out until you're happy. – ysalmi Mar 16 '14 at 22:58
  • I tried that, and it did not work. Interestingly enough, i downloaded the font used in the example and FT_New_Face() return an error.... I start thinking my machine/OS/configuration has something to do with this. My last result was to add EVERY src-file needed by the example program directly to see where the faulty line was exactly. Thank you anyway for reading through all that, I go and test it on another PC/laptop. I also contacted the Harfbuzz mailing list. – BeschBesch Mar 17 '14 at 16:15

0 Answers0