仅在调试模式下FT_Load_Char之后的Freetype2访问冲突

时间:2014-06-11 18:19:08

标签: c++ opengl visual-studio-debugging freetype2

对于X-Plane插件的FreeType2实现有些麻烦。我使用的是freetype实现,我没有写,但好消息是,它在发布模式下有效。我无法在调试模式中超越这一点,这意味着我无法调试程序的任何其他部分。如果有人对可能出现的问题有任何想法,或者我如何防止调试中出现问题,那就太棒了。这是代码:

// We iterate through every letter that we care about
// and record the tallest letter and the width of all
// letters combined as well as the widest letter.
for(int n = FM_BASE_ASCII_RANGE; n <= FM_PEAK_ASCII_RANGE; ++n)
{
    if(FT_Load_Char(*inFace, n, FT_LOAD_RENDER))
        continue;

    // If the bitmap doesn't exist, we have nothing to do
    //access violation happens when executing the next line in debug
    if(!(*inFace)->glyph->bitmap.rows || !(*inFace)->glyph->bitmap.width) 
        continue;

    int width  = (*inFace)->glyph->metrics.width / 64.0;
    int height = (*inFace)->glyph->metrics.height / 64.0;

    // If any of the sizes are 0, we have nothing to do
    if(!(*inFace)->glyph->metrics.width || !(*inFace)->glyph->metrics.height)
        continue;

    if(height > maxHeight)
        maxHeight = height;

    // Add this to our sum with some room for padding as well
    curRowWidth += width + FM_PIX_PADDING;

    // If it doesn't fit, we add a new row and put it there
    if(curRowWidth > FM_DEFAULT_TEX_WIDTH)
    {
        nRows++;
        curRowWidth = width + FM_PIX_PADDING;
    }
}

为每种字体调用上面的代码并循环显示字母以计算我认为的大小。首次使用加载的第一个字体时会发生错误。字体渲染效果很好,在发布模式下效果很好。

我不确定它是否重要,但如果我在此访问冲突之前中断并评估(* inFace) - &gt; glyph-&gt;位图,我看到行和宽度为0 ...但是位图.buffer列为0x0000~。

此外,在循环的第一次迭代中n为32。 FT_Load_Char返回时没有错误。

我在Win 7 64位中使用Windows 7.1 SDK运行Visual Studio 2010,这是一个64位项目。我刚刚升级到freetype 2.5.3,但在我以前的版本2.4.12中遇到了同样的问题。

如果有人可以提供帮助,那对我很有帮助,谢谢!

编辑:这是运行时错误周围的反汇编部分:

for(int n = FM_BASE_ASCII_RANGE; n <= FM_PEAK_ASCII_RANGE; ++n)
000007FEE531F29A  mov         dword ptr [n],20h  
000007FEE531F2A2  jmp         FontMgr::CalcTexSize+6Eh (7FEE531F2AEh)  
000007FEE531F2A4  mov         eax,dword ptr [n]  
000007FEE531F2A8  inc         eax  
000007FEE531F2AA  mov         dword ptr [n],eax  
000007FEE531F2AE  cmp         dword ptr [n],0FEh  
000007FEE531F2B6  jg          FontMgr::CalcTexSize+178h (7FEE531F3B8h)  
{
    if(FT_Load_Char(*inFace, n, FT_LOAD_RENDER))
000007FEE531F2BC  mov         r8d,4  
000007FEE531F2C2  mov         edx,dword ptr [n]  
000007FEE531F2C6  mov         rax,qword ptr [inFace]  
000007FEE531F2CB  mov         rcx,qword ptr [rax]  
000007FEE531F2CE  call        FT_Load_Char (7FEE5360790h)  
000007FEE531F2D3  test        eax,eax  
000007FEE531F2D5  je          FontMgr::CalcTexSize+99h (7FEE531F2D9h)  
        continue;
000007FEE531F2D7  jmp         FontMgr::CalcTexSize+64h (7FEE531F2A4h)  

    // If the bitmap doesn't exist, we have nothing to do
            if(!(*inFace)->glyph->bitmap.rows ||!(*inFace)->glyph->bitmap.width)
000007FEE531F2D9  mov         rax,qword ptr [inFace]  
000007FEE531F2DE  mov         rax,qword ptr [rax]  
000007FEE531F2E1  mov         rax,qword ptr [rax+6Ch]  
->000007FEE531F2E5  cmp         dword ptr [rax+60h],0  
000007FEE531F2E9  je          FontMgr::CalcTexSize+0BDh (7FEE531F2FDh)  
000007FEE531F2EB  mov         rax,qword ptr [inFace]  
000007FEE531F2F0  mov         rax,qword ptr [rax]  
000007FEE531F2F3  mov         rax,qword ptr [rax+6Ch]  
000007FEE531F2F7  cmp         dword ptr [rax+64h],0  
000007FEE531F2FB  jne         FontMgr::CalcTexSize+0BFh (7FEE531F2FFh)  
        continue;
000007FEE531F2FD  jmp         FontMgr::CalcTexSize+64h (7FEE531F2A4h)  

0 个答案:

没有答案