C++ Box2D和dll“;访问冲突读取位置“;

C++ Box2D和dll“;访问冲突读取位置“;,c++,dll,visual-studio-2013,box2d,access-violation,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

是的,所以当我试图编译我的项目时,我有一个小问题

我有一个制作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!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]  
GamePlayerdy.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_动态车身代码不会崩溃

还有一点需要注意的是,如果在dll中执行相同的代码,那么即使从exe代码调用,它也可以正常工作

尽管需要boost、sfml和box2d进行编译,但整个代码都位于


感谢是进步

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

b2PolygonShape shape;
b2FixtureDef fixture();
一开始

b2BodyDef def();

虽然仅仅添加()会导致错误,但我确实将所有内容转换为指针并在堆上创建了它。虽然这可能是一个愚蠢的问题,但在将对象转换为指针之后,您是否删除了它们?@Miniwoffer b2_dynamicBody从何而来?我认为在读取似乎匹配的调试数据时,它是一个包含数字2的单元。