Freetype2 在 WoW64 下失败

发布于 2024-10-07 04:19:53 字数 2198 浏览 7 评论 0原文

我使用 freetype2(2.3.9) 构建了一个 tff 到 D3D 纹理函数,以从字体生成灰度图。它在本机 win32 下工作得很好,但是,在 WoW64 上它只是爆炸(嗯,FT_DoneFT_Load_Glyph )。从一些调试来看,这似乎是 HeapFree 的问题,由 FT_Free 中的 free 调用。

我知道它应该可以工作,因为像 WCIII 这样的游戏,据我所知使用 freetype2,运行良好,这是我的代码,删除了 D3D 代码(它本身不会导致任何问题):

    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 返回用 new 分配的块。

作为第二个问题,我想使用像素大小渲染字体,我遇到了 FT_Set_Pixel_Sizes,但我不确定这是否会拉伸字体以适合大小,或将其限制到某个大小。我想做的是将所有字形渲染为 24px(此处为 MS Word 大小),然后将其转换为 32px 区域中的带符号距离场。

更新

经过多次摆弄,我得到了一个可以运行的测试应用程序,这让我认为问题是由线程引起的,因为我的代码在辅助线程中运行。我已经使用多线程 DLL 将 freetype 编译成静态库,我的应用程序使用多线程库。看看我是否可以设置多线程测试。

还更新到 2.4.4,看看问题是否是一个已知但已修复的错误,但没有帮助。

更新 2

经过一番摆弄,结果发现我没有使用 2.4.4 的正确库 -.- 修复该问题后,测试应用程序可以 100% 工作,但主应用程序仍然崩溃调用FT_Done_Face,似乎仍然是Windows内存堆管理中的崩溃。 freetype2 是否有可能存在一个 bug,导致它在用户线程下崩溃?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文