Freetype2 failing under WoW64

Posted by Necrolis on Stack Overflow See other posts from Stack Overflow or by Necrolis
Published on 2010-12-13T06:56:47Z Indexed on 2010/12/21 6:54 UTC
Read the original article Hit count: 368

Filed under:
|
|

I built a tff to D3D texture function using freetype2(2.3.9) to generate grayscale maps from the fonts. it works great under native win32, however, on WoW64 it just explodes (well, FT_Done and FT_Load_Glyph do). from some debugging, it seems to be a problem with HeapFree as called by free from FT_Free.

I know it should work, as games like WCIII, which to the best of my knowledge use freetype2, run fine, this is my code, stripped of the D3D code(which causes no problems on its own):

    FT_Face pFace = NULL;
    FT_Error nError = 0;
    FT_Byte* pFont = static_cast<FT_Byte*>(ARCHIVE_LoadFile(pBuffer,&nSize));
    if((nError = FT_New_Memory_Face(pLibrary,pFont,nSize,0,&pFace)) == 0)
    {
        FT_Set_Char_Size(pFace,nSize << 6,nSize << 6,96,96);
        for(unsigned char c = 0; c < 95; c++)
        {
            if(!FT_Load_Glyph(pFace,FT_Get_Char_Index(pFace,c + 32),FT_LOAD_RENDER))
            {
                FT_Glyph pGlyph;
                if(!FT_Get_Glyph(pFace->glyph,&pGlyph))
                {
                    LOG("GET: %c",c + 32);
                    FT_Glyph_To_Bitmap(&pGlyph,FT_RENDER_MODE_NORMAL,0,1);
                    FT_BitmapGlyph pGlyphMap = reinterpret_cast<FT_BitmapGlyph>(pGlyph);
                    FT_Bitmap* pBitmap = &pGlyphMap->bitmap;
                    const size_t nWidth = pBitmap->width;
                    const size_t nHeight = pBitmap->rows;
                    //add to texture atlas
                }
            }
        }
    }
    else
    {
        FT_Done_Face(pFace);
        delete pFont;   
        return FALSE;
    }

    FT_Done_Face(pFace);
    delete pFont;
    return TRUE;
}

ARCHIVE_LoadFile returns blocks allocated with new.

As a secondary question, I would like to render a font using pixel sizes, I came across FT_Set_Pixel_Sizes, but I'm unsure as to whether this stretches the font to fit the size, or bounds it to a size. what I would like to do is render all the glyphs at say 24px (MS Word size here), then turn it into a signed distance field in a 32px area.

Update

After much fiddling, I got a test app to work, which leads me to think the problems are arising from threading, as my code is running in a secondary thread. I have compiled freetype into a static lib using the multithread DLL, my app uses the multithreaded libs. gonna see if i can set up a multithreaded test.

Also updated to 2.4.4, to see if the problem was a known but fixed bug, didn't help however.

Update 2

After some more fiddling, it turns out I wasn't using the correct lib for 2.4.4 -.- after fixing that, the test app works 100%, but the main app still crashes when FT_Done_Face is called, still seems to be a crash in the memory heap management of windows. is it possible that there is a bug in freetype2 that makes it blow up under user threads?

© Stack Overflow or respective owner

Related posts about visual-c++

Related posts about wow64