调试模式中未处理的异常,但在发布时工作正常

时间:2012-01-01 02:15:56

标签: c++ exception release 64-bit unhandled

我不知道为什么,但是这个代码在64位编译时在调试模式下出现此错误:

  

OpenGL.exe中0x000000013f488f55处的未处理异常:0xC0000005:   访问冲突读取位置0x000000053f4d9778。

然而,在32位编译时,它在发布模式下运行完美,并且调试和发布都很好!非常感谢帮助。

我正在使用Visual Studio 2010。

float g_History[20] = { 0.0f };
const float g_WeightModifier = 0.25f;

void CInput::SmoothMouseMovement()
{
    if(!m_SmoothMouse) return;

    for(UINT i = 0; i < 10; i++)
    {
        g_History[i * 2] = g_History[(i - 1) * 2]; // This line gives the error
        g_History[i * 2 + 1] = g_History[(i - 1) * 2 + 1];
    }

    g_History[0] = m_MouseState.X;
    g_History[1] = m_MouseState.Y;

    float AverageX = 0.0f;
    float AverageY = 0.0f;
    float AverageTotal = 0.0f;
    float WeightModifier = 1.0f;

    for(UINT i = 0; i < 10; i++)
    {
        AverageX += g_History[i * 2] * WeightModifier;
        AverageY += g_History[i * 2 + 1] * WeightModifier;
        AverageTotal += 1.0f * WeightModifier;
        WeightModifier *= g_WeightModifier;
    }

    m_MouseState.X = AverageX / AverageTotal;
    m_MouseState.Y = AverageY / AverageTotal;
}

1 个答案:

答案 0 :(得分:6)

第一次循环,g_History[(i - 1) * 2]将等同于g_History [-2],这显然是一个糟糕的访问。关于如何使用32v64和debug v release安排内存,这简直是巧合。无论您的应用是否崩溃,该行都是错误的。

相关问题