好吧,我正在制作自己的简单引擎,我已经实现了一个成功的ECS,现在我正在尝试实现Box2D的物理功能,并且我有一些所以我有一个类型为“RigidBody2D”的组件,它进行了一些物理计算,看起来像这样(注意我使用Unity3D类似的组件,它们包含启动,唤醒和更新功能,我不使用系统):Box2D:断言失败,Wntdll.pdb未加载
'RigidBody.h'
#pragma once
#include "Component.h"
class RigidBody2D : public Component
{
private:
float Density = 1.f;
float Friction = 1.f;
b2BodyDef bodyDef;
b2FixtureDef fixtureDef;
b2PolygonShape dynamicBox;
public:
Transfrm* Trans;
b2Body* Body;
RigidBody2D() : Component("RigidBody2D") {
Trans = new Transfrm(b2Vec2(0.f, 0.f), 0.f, b2Vec2(1.f, 1.f));
bodyDef.type = b2_dynamicBody;
bodyDef.position.Set(Trans->Position.x, Trans->Position.y);
Body = CurrentPhysicsWorld->CreateBody(&bodyDef);
dynamicBox.SetAsBox(1.0f, 1.0f);
fixtureDef.shape = &dynamicBox;
fixtureDef.density = GetDensity();
fixtureDef.friction = GetFriction();
Body->CreateFixture(&fixtureDef); // The Line That Causes trouble
};
~RigidBody2D();
};
好了,一切都看起来不错,我基本上复制从Box2D的示例中的例子:“HelloWorld.cpp”,并将其落实到一类,我在控制台中运行这个后,我得到这个消息:
"Assertion failed: m_nodeCount == m_nodeCapacity, file ..\..\Box2D\Collision\b2DynamicTree.cpp, line 58"
一些测试后,我发现,造成这个问题的路线是:
Body->CreateFixture(&fixtureDef);
当我注释此行,程序运行时,则Visual Studio的2015年显示了我一个消息:"Wntdll.pdb Not Loaded, wntdll.pdb contains the debug information required to find the source for the module ntdll.dll"
我我不确定是什么导致了这个问题,或者为什么这是我第一次使用Box2D。
编辑: 一个MVCE必须是这一点,就需要建立的Box2D与该项目能够运行该代码:
#include <Box2D.h>
b2World CurrentWorld;
class World {
public:
b2World physicsWorld;
World() { CurrentWorld = this->physicsWorld; };
~World() {};
};
class RigidBody2D
{
public:
b2Body* Body;
b2BodyDef bodyDef;
b2FixtureDef fixtureDef;
b2PolygonShape dynamicBox;
RigidBody2D() {
bodyDef.type = b2_dynamicBody;
bodyDef.position.Set(Trans->Position.x, Trans->Position.y);
Body = CurrentWorld->CreateBody(&bodyDef);
dynamicBox.SetAsBox(1.0f, 1.0f);
fixtureDef.shape = &dynamicBox;
Body->CreateFixture(&fixtureDef);
}
~RigidBody2D() {};
};
int main() {
World wrld = World();
RigidBody2D body = RigidBody2D();
return 0;
}
可能有些内存损坏。提供[mvce](http://stackoverflow.com/help/mcve),这样我们就可以编译并运行代码来检查它。 – folibis
@folibis编辑我的文章,并添加了一个MVCE,请确保您测试了它。 – kooldart