2011-07-27 24 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