2011-07-27 25 views
0

我正在试图在box2d游戏中使用提升。但是当我创建b2world时,会导致崩溃。用box2d提升

#include <Box2d/Box2D.h> 
#include <boost/filesystem/operations.hpp> 
#include <boost/filesystem/path.hpp> 

namespace fs = boost::filesystem; 


int main(int argc, char *argv[]) 
{ 
    b2World *world = new b2World(b2Vec2(0.0f, -10.0f), true); 

    fs::path full_path(fs::initial_path<fs::path>()); 

    delete world; 

    return 0; 
} 

当我用box2d或boost代码注释字符串时,它工作正常。但他们不想一起工作。

错误:Game.exe中0x5d9031ea(msvcr90d.dll)未处理的异常:0xC0000005:访问冲突读取位置0xccccccc0。

> msvcr90d.dll!operator delete(void * pUserData=0xcccccccc) Line 52 + 0x3 bytes C++ 
    msvcp90d.dll!std::allocator<unsigned short>::deallocate(unsigned short * _Ptr=0xcccccccc, unsigned int __formal=3435973837) Line 146 + 0x9 bytes C++ 
    msvcp90d.dll!std::basic_string<unsigned short,std::char_traits<unsigned short>,std::allocator<unsigned short> >::_Tidy(bool _Built=true, unsigned int _Newsize=0) Line 2168 C++ 
    msvcp90d.dll!std::basic_string<unsigned short,std::char_traits<unsigned short>,std::allocator<unsigned short> >::~basic_string<unsigned short,std::char_traits<unsigned short>,std::allocator<unsigned short> >() Line 917 C++ 
    Game.exe!boost::filesystem3::path::~path() + 0x2e bytes C++ 
    Game.exe!main(int argc=1, char * * argv=0x003a4ca0) Line 32 + 0x19 bytes C++ 
    Game.exe!__tmainCRTStartup() Line 582 + 0x19 bytes C 

只生成调试模式。

无论我在哪里创建b2World对象:在full_path()之后或不是。即使我在项目中的另一个类或文件中创建了b2World对象,也会产生错误。

+1

你会很快发现,如果你不包含超过“它崩溃”,我们通常不可能帮助调试你的错误。它如何崩溃?它会产生错误吗?你是否添加了一个断点来查看它是否通过某一行? –

+0

msvcr90d.dll!运算符删除(void * pUs ...第52行 msvcp90d.dll!std :: allocat ...第146行+ 0x9字节 msvcp90d.dll!std :: basic_string ,std :: allocator ,std :: allocator > ::〜 game_sys ,std :: allocator >()行917 Game.exe!boost :: filesystem3 :: path ::〜path() Game.exe! main(int argc = 1,char * * argv = 0x002e4ca0) 有调用堆栈,仅在调试模式下产生错误 – Raman

+0

@Raman:把它放在你的答案中并格式化它 –

回答

0

嗯,这将是非常困难的,你指出问题的确切原因,但它似乎你有一个堆腐败。因为效果(崩溃)通常可以在以后很久以及在代码的一些不相关的部分中看到,因此找到罪魁祸首(一段代码覆盖或释放一些本应该不存在的内存)可能非常棘手;

您是否在“代码生成”选项卡下的运行时库设置下尝试了其他选项?有时将不同的CRT与不同的CRT混合会导致崩溃(虽然通常会出现链接错误)。

然后,如果没有任何帮助,我会建议你尝试隔离问题并创建一个问题显示的最小项目,这是很耗时的,但可以帮助很多,因为如前所述,这些问题可能很难找到。

从那里你也可以使用一些额外的工具,可以帮助跟踪堆损坏。例如,您可以使用gflags(来自Windows调试工具包)为应用程序激活“页堆”选项,这将在检测到堆损坏时使调试器中断执行。

+0

我不使用MFC。请多加注意。 – Raman

+0

Ops我坏,不知道我在哪里看到MFC,我现在编辑了我的答案。其余的依然适用 - 我认为你正在处理堆腐败,你可以谷歌或搜索堆栈溢出来获得一些技巧,如何解决这些问题(正如已经指出的那样,它可能是相当棘手和耗时) – floyd73