【发布时间】:2015-01-17 15:04:26
【问题描述】:
是的,所以我在尝试编译我的项目时遇到了一点问题。
我有一个项目制作一个 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编译。
先谢谢了
【问题讨论】:
标签: c++ dll visual-studio-2013 box2d access-violation