Box2D和dll"访问违规读取位置"

时间:2015-01-17 15:04:27

标签: c++ dll visual-studio-2013 box2d access-violation

是的,所以当我尝试编译我的项目时,我有一点问题。

我有一个项目创建了一个dll,另一个项目使用它来创建一个exe,两个项目链接到Box2D.lib(这是什么导致错误?,如果是这样,是什么链接静态库的正确方法当dll和exe都使用时

b2World的构造由DLL代码完成,但下面的类由exe部分完成。

b2BodyDef def;

def.position = b2Vec2(10, 10);
def.type = b2_dynamicBody;

b2Body* body;
body = world->CreateBody(&def);

b2Vec2 sizeboxsim(10,10);
b2PolygonShape shape;
b2FixtureDef fixture;
fixture.shape = &shape;//this where the program returns the error

body->CreateFixture(&fixture);

错误如下:

GamePlayground.exe中0x010B80C1处的未处理异常:0xC0000005:访问冲突读取位置0x41200000。

堆栈如下:

GamePlayground.exe!b2BlockAllocator::Allocate(int)
GamePlayground.exe!b2PolygonShape::Clone(class b2BlockAllocator *)
GamePlayground.exe!b2Fixture::Create(class b2BlockAllocator *,class b2Body *,struct b2FixtureDef const *)
GamePlayground.exe!b2Body::CreateFixture(struct b2FixtureDef const *)
GamePlayground.exe!testClass::testClass(b2World * world)
GamePlayground.exe!PlaygroundGame::PlaygroundGame()
GamePlayground.exe!main()
[External Code] 
[Frames below may be incorrect and/or missing, no symbols loaded for kernel32.dll]  

有趣的是,如果您同时删除def.position = b2Vec2(10, 10);def.type = b2_dynamicBody;,则代码不会崩溃。

还要注意如果在dll中完成相同的代码,即使从exe代码调用它也能正常工作。

整个代码位于https://github.com/Miniwoffer/Phoenix,尽管你需要boost,sfml和box2d来编译。

谢谢是提前

1 个答案:

答案 0 :(得分:0)

似乎默认情况下不会创建对象。试试

b2PolygonShape shape;
b2FixtureDef fixture();

开头

b2BodyDef def();