0

只是试图在 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);
   }
4

1 回答 1

0

正是 iforce2d 在评论中所说的,您需要创建一个指向b2World并调用new它的指针。你不能直接调用它constructor,而不调用new它。显然正确的说法是——

b2World* world = new b2World(gravity, doSleep); 
于 2013-01-22T23:35:14.577 回答