My app crashes when i try to use the features of b2Body from within my NSObject class.
Here is the interface of my class:
Code:
#import <Foundation/Foundation.h>
#import "Box2D.h"
#import "GLES-Render.h"
#import "cocos2d.h"
#import "HelloWorldScene.h"
@interface Magnet : NSObject {
b2Body* body;
}
@property (readwrite,assign) b2Body* body;
@end
And here is how i declare it in HelloWorldScene.h:
Code:
#import "cocos2d.h"
#import "Box2D.h"
#import "GLES-Render.h"
#import <UIKit/UIKit.h>
#import "Magnet.h"
@class Magnet;
@interface HelloWorld : CCLayer
{
b2World* world;
GLESDebugDraw *m_debugDraw;
Magnet *magnet;
}
And here is how i access the b2Body in magnet, in HelloWorldScene.mm:
Code:
b2BodyDef bodyDef2;
bodyDef2.type = b2_staticBody;
bodyDef2.position.Set(300/PTM_RATIO, 150/PTM_RATIO);
bodyDef2.userData = sprite2;
magnet.body = world->CreateBody(&bodyDef2);
// Define another box shape for our dynamic body.
//b2PolygonShape dynamicBox;
b2CircleShape dynamicBox2;
//dynamicBox.SetAsBox(1.0f, 1.0f);//These are mid points for our 1m box
dynamicBox2.m_radius = 0.49;
// Define the dynamic body fixture.
b2FixtureDef fixtureDef2;
fixtureDef2.shape = &dynamicBox2;
fixtureDef2.density = 1.3f;
fixtureDef2.friction = 1.0f;
magnet.body->CreateFixture(&fixtureDef2);
Is there any problem with my code?
Im receiving a SIGABRT in the Box2D sourcefiles in the CreateFixture() function... What should I do?