0

Just trying to set up box2d world on Marmalade project brings access violation :

#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);

}

debugging it, shows that at b2Settings.cpp "malloc(1024)" causes access violation

     #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);
   }
Delcasda
  • 371
  • 4
  • 13
  • 1
    How about if the world is created on the heap, eg. b2World* world = new b2World(gravity, doSleep); – iforce2d Dec 19 '12 at 17:06

1 Answers1

0

Exactly what iforce2d has said in the comment, you need to create a pointer to b2World and call new on it. You can't directly call it's constructor, without calling new on it. Obviously the correct statement would be -

b2World* world = new b2World(gravity, doSleep); 
0xC0DED00D
  • 19,522
  • 20
  • 117
  • 184