I implemented the cpMouse code into my project. There are no errors or warnings, but when I run the program it quits and the console reads "Assertion fail: (body != NULL), function cpShapeInit."
Here is my code:
extern void makeStaticBox(float x, float y, float width, float height);
cpSpace *space;
cpBody *staticBody
...
Sprite *Block1 = [[Sprite spriteWithFile:@"1x1.png"] retain];
Block1.position = cpv(160,240);
[self addChild: Block1];
cpVect verts[] = {
cpv(-36,-36),
cpv(-36, 36),
cpv(36, 36),
cpv(36,-36),
};
cpBody *Block1Body = cpBodyNew(50.0f, INFINITY);
Block1Body->p = cpv(160,240);
Block1Body->v = cpv(0, 0);
cpSpaceAddBody(space, Block1Body);
cpShape * Block1Shape = cpPolyShapeNew(Block1Body, 4, verts, cpvzero);
Block1Shape->e = 0.9f;
Block1Shape->u = 0.9f;
Block1Shape->data = Block1;
Block1Shape->collision_type = 0;
cpSpaceAddShape(space, Block1Shape);
CGSize s = [[Director sharedDirector] winSize];
int margin = 4;
int dmargin = margin*2;
makeStaticBox(margin, margin, s.width - dmargin, s.height - dmargin); //This references a static box the size of the window in a C class.
}
return self;
}
Please help!
cpMouse Implementation Problems
-
- Posts: 5
- Joined: Thu Aug 13, 2009 9:14 pm
- Contact:
- Tam Toucan
- Posts: 141
- Joined: Tue Jun 23, 2009 4:26 pm
- Contact:
Re: cpMouse Implementation Problems
Can't you get a stack trace? That would help. You are calling Hmmmm, and you haveWhere does that get set up and referenced?
Code: Select all
makeStaticBox(margin, margin, s.width - dmargin, s.height - dmargin); //This references a static box the size of the window in a C class.
Code: Select all
cpBody *staticBody
-
- Posts: 5
- Joined: Thu Aug 13, 2009 9:14 pm
- Contact:
Re: cpMouse Implementation Problems
The cpBody *staticBox is referenced in the static box created in another class. Here is the code:
extern cpSpace* space;
extern cpBody *staticBody;
void makeStaticBox(float x, float y, float width, float height){
cpShape * shape;
shape = cpSegmentShapeNew(staticBody, cpv(x,y), cpv(x+width, y), 0.0f); //Specifically Here
shape->e = 1.0; shape->u = 1.0;
cpSpaceAddStaticShape(space, shape);
shape = cpSegmentShapeNew(staticBody, cpv(x+width, y), cpv(x+width, y+height ), 0.0f);
shape->e = 1.0; shape->u = 1.0;
cpSpaceAddStaticShape(space, shape);
shape = cpSegmentShapeNew(staticBody, cpv(x+width, y+height), cpv(x, y+height ), 0.0f);
shape->e = 1.0; shape->u = 1.0;
cpSpaceAddStaticShape(space, shape);
shape = cpSegmentShapeNew(staticBody, cpv(x, y+height ), cpv(x, y), 0.0f);
shape->e = 1.0; shape->u = 1.0;
cpSpaceAddStaticShape(space, shape);
}
Thanks! I am working on a stack trace.
extern cpSpace* space;
extern cpBody *staticBody;
void makeStaticBox(float x, float y, float width, float height){
cpShape * shape;
shape = cpSegmentShapeNew(staticBody, cpv(x,y), cpv(x+width, y), 0.0f); //Specifically Here
shape->e = 1.0; shape->u = 1.0;
cpSpaceAddStaticShape(space, shape);
shape = cpSegmentShapeNew(staticBody, cpv(x+width, y), cpv(x+width, y+height ), 0.0f);
shape->e = 1.0; shape->u = 1.0;
cpSpaceAddStaticShape(space, shape);
shape = cpSegmentShapeNew(staticBody, cpv(x+width, y+height), cpv(x, y+height ), 0.0f);
shape->e = 1.0; shape->u = 1.0;
cpSpaceAddStaticShape(space, shape);
shape = cpSegmentShapeNew(staticBody, cpv(x, y+height ), cpv(x, y), 0.0f);
shape->e = 1.0; shape->u = 1.0;
cpSpaceAddStaticShape(space, shape);
}
Thanks! I am working on a stack trace.
- Tam Toucan
- Posts: 141
- Joined: Tue Jun 23, 2009 4:26 pm
- Contact:
Re: cpMouse Implementation Problems
Still don't see the code where you set up staticBody i.e. you callbut that will crash unless staticBody has been created i.e. staticBody will be NULL so the assert will trigger.
Code: Select all
shape = cpSegmentShapeNew(staticBody,...
-
- Posts: 5
- Joined: Thu Aug 13, 2009 9:14 pm
- Contact:
Re: cpMouse Implementation Problems
Thanks so much!
Who is online
Users browsing this forum: No registered users and 14 guests