只是试图在 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 "malloc(1024)" 导致访问冲突
#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);
}