簡體   English   中英

調試模式下未處理的異常,但在發行版中工作正常

[英]Unhandled exception in debug mode but works fine in release

我不知道為什么,但是下面的這段代碼在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;
}

第一次通過循環, g_History[(i - 1) * 2]將等同於g_History [-2],這顯然是錯誤的訪問。 這與32v64和debug v release如何安排內存只是巧合。 無論您的應用程序是否崩潰,該行都是錯誤。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM