在调试模式下未处理的异常,但在发布中工作正常
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和调试v版本的内存安排上的巧合。无论你的应用程序是否崩溃,这一行都是一个错误。
相关文章:
- 布尔比较运算符是如何在C++中工作的
- <<操作员在下面的行中工作
- CV_OCL_RUN宏如何在OpenCV(版本3.4.5)的goodFeaturesToTrack实现中工作?
- std::unique_ptr 在 GCC 中工作,但不能在 Visual Studio 中编译
- 声明C++具有动态大小的数组类型在 Linux 中工作正常,但不能在 Windows 中工作
- C++ assigment std::list:<typename>:itrator 在 main 中工作,但在方法中它不起作用
- 如何使实例化在我的 OpenGL 程序中工作?
- 如何使HTML5电子邮件验证正则表达式在C++中工作?
- 我的 SDL2 程序需要哪些二进制文件,以便它在另一台未安装 SDL2 的计算机中工作
- 代码在 CodeSignal 中工作不正确。不确定这是否是我的代码缺陷
- 当输入在带有空格的单行中给出时,cin 如何在 while 循环中工作?
- 代码在Visual Studio 2017中不起作用,但在VS代码中工作
- 请发现它在 dev 中工作的错误,但在 hackerrank 中不起作用
- 有没有办法让这个模板在 cpp 中工作?
- 如何使函数在派生类中工作?
- OpenCV Tracker 属性访问在 ARM 上因 SEGFAULT 而失败,但在 X86_64 中工作
- 程序在CLion IDE中工作,但exe不起作用
- "lock cmpxchg"如何在装配中工作?
- 如何使这个 Foor 循环在这个问题中工作?
- .exe应用程序在windows10中创建新模块时抛出错误,但在windows7中工作正常