c++ - 当我为调试 Lua 编译我的程序时运行良好,但为什么我为发布编译它我得到一个 c0000005 错误

标签 c++ visual-studio-2010 lua

我正在将 LUA 用于 SDL 项目。我从这里 (http://sourceforge.net/projects/luabinaries/files/5.2/Windows%20Libraries/Dynamic/) (lua-5.2_Win32_dll10_lib.zip) 下载了预编译的 LIB 和 DLL 文件,并将其合并到我的项目中。当我构建调试版本时,应用程序运行 100% 正常。当我将它设置为 Release模式并按下 Visual Studio 中的播放按钮时,它也运行良好。

但是,如果我通过在文件夹中双击运行 Release 文件,我会收到带有 lua52.dll 的错误 c0000005。

我正在运行 MicroSoft Visual C++ 2010 Express。

我经历了删除行直到它开始工作,导致错误的行是。

void aiBrainmanager::run(string holdData){

int errfunc = 0;
int s;
int s = luaL_loadstring(L, holdData.c_str());

if ( s==0 ) {
    s = lua_pcall(L, 0, LUA_MULTRET, errfunc);
}
if (errfunc !=0) {

}
if (s !=0) {

    aiBrainmanager::target->stopWorking();
}


}

知道什么设置有问题或如何解决。

最佳答案

0xc0000005 是内存违规。它在调试中工作的事实意味着许多可能的事情。

  1. 内存未被初始化或设置正确(在调试中它被初始化为 0)因此字符串被终止,例如。
  2. 内存要求大于缓冲区允许的范围(在调试中可以填充)。
  3. 你的代码在调试中做的事情与编译时不同(#if 等)

查看您的代码我会查看:

为什么你检查错误然后什么都不做?????

if (errfunc !=0) { 
 // What happens in here??????
} 

The lua_pcall function returns 0 in case of success or one of the following error codes (defined in lua.h):

  • LUA_ERRRUN: a runtime error.

  • LUA_ERRMEM: memory allocation error. For such errors, Lua does not call the error handler function.

  • LUA_ERRERR: error while running the error handler function

我想你会发现你得到了一个LUA_ERRMEM

关于c++ - 当我为调试 Lua 编译我的程序时运行良好,但为什么我为发布编译它我得到一个 c0000005 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10051614/

相关文章:

c++ - 尝试使用 lua 错误调用对象方法时 luabind 中止

c++ - JOYINFOEX::dwButtonNumber 是什么?

c++ - 为什么 delete 运算符可以用在 const 上下文中?

visual-studio-2010 - 如何在 Visual C++ 2010 中创建安装程序?

visual-studio-2010 - 生成失败,错误 MSB3073,退出代码 9009

visual-studio-2010 - 我现在应该开始使用 VS2010 Beta 2 进行开发工作吗?

lua - 从 Corona 的多个 lua 文件生成单个 lua 字节码文件

c - 错误加载模块 undefined symbol : luaL_setfuncs

c++ - 将外部 C 库加载到现有的 C++ 项目中(例如 ffmpeg/libavcodec - 一步一步)

c++ - 在 cmake 中设置最低版本的 boost