试图在Marmalade项目上设置box2d世界会带来访问冲突:
#include "s3e.h"
#include "Iw2D.h"
#include "game.h"
#include "Box2D\Box2D.h"
CGame::CGame()
: m_Position(0,0)
, m_Size(Iw2DGetSurfaceHeight() / 10, Iw2DGetSurfaceHeight() / 10)
{
b2Vec2 gravity(0.0f, -10.0f);
bool doSleep = true;
b2World world(gravity, doSleep); <------this line is the one
b2BodyDef groundBodyDef;
groundBodyDef.position.Set(0.0f, -10.0f);
b2Body* groundBody = world.CreateBody(&groundBodyDef);
b2PolygonShape groundBox;
groundBox.SetAsBox(50.0f, 10.0f);
groundBody->CreateFixture(&groundBox, 0.0f);
}
调试它,显示在b2Settings.cpp&#34; malloc(1024)&#34;导致访问冲突
#include <Box2D/Common/b2Settings.h>
#include <cstdlib>
b2Version b2_version = {2, 2, 0};
// Memory allocators. Modify these to use your own allocator.
void* b2Alloc(int32 size)
{
return malloc(size); <----this is the one
}
void b2Free(void* mem)
{
free(mem);
}
答案 0 :(得分:0)
正如iforce2d在评论中所说的那样,你需要创建一个指向b2World
的指针并在其上调用new
。您无法直接调用它constructor
,而无需在其上调用new
。显然正确的陈述是 -
b2World* world = new b2World(gravity, doSleep);