【问题标题】:Box2D and dll "Access violation reading location"Box2D和dll“访问冲突读取位置”
【发布时间】: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


    【解决方案1】:

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

    b2PolygonShape shape;
    b2FixtureDef fixture();
    

    开始

    b2BodyDef def();
    

    【讨论】:

    • 虽然只是添加 () 会导致错误,但我确实将所有内容都转换为指针并在堆上创建它。但仍然导致错误。
    • 可能是个愚蠢的问题,但是在将对象转换为指针之后,你有没有为它们去掉&?
    • @Miniwoffer b2_dynamicBody 来自哪里?
    • 它是一个包含数字 2 的 uint,我认为 box2dflash.org/docs/2.1a/reference/Box2D/Dynamics/b2Body.html 在读取似乎匹配的调试数据时。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-31
    • 2016-05-28
    • 2017-01-09
    • 2014-11-09
    • 1970-01-01
    相关资源
    最近更新 更多