when spawning a ball:
Code: Select all
this->b[i].cp_shape->collision_type = BRK_COLLISION_TYPE__BALL;
Code: Select all
this->cp_shape->collision_type = BRK_COLLISION_TYPE__PADDLE;
Code: Select all
cpSpaceAddCollisionHandler(brk->cp_space,
BRK_COLLISION_TYPE__BALL,
BRK_COLLISION_TYPE__PADDLE,
&BRK_collision__ball_2_paddle, NULL, NULL, NULL, NULL);
when reseting a ball:
(this happens to all balls before and between levels, and naturally cp_body and cp_shape get properly initialized as NULL in the ball constructor)
Code: Select all
if (this->cp_body != NULL)
{
cpSpaceRemoveBody(brk->cp_space, this->cp_body);
cpBodyFree(this->cp_body);
this->cp_body = NULL;
}
if (this->cp_shape != NULL)
{
cpSpaceRemoveShape(brk->cp_space, this->cp_shape);
cpShapeFree(this->cp_shape);
this->cp_shape = NULL;
}
Code: Select all
int BRK_collision__ball_2_paddle ( cpArbiter *arb, cpSpace *space, void *data )
{
cpShape *ball_shape, *player_shape;
cpArbiterGetShapes(arb, &ball_shape, &player_shape);
brk_ball_c *ball = (brk_ball_c *) ball_shape->data;
brk_player_c *player= (brk_player_c *) player_shape->data;
if (ball && player)
ball->last_touched_by = player->index;
else
{
printf ("WTF?! ");
if (!ball)
printf (" no ball ");
if (!player)
printf (" no player ");
printf ("\n");
}
return true;
}
I end up with a lot of "WTF?! no ball" in stdout (but never on the first level it seems) That means there is one or more lingering shapes that have collision_type == BRK_COLLISION_TYPE__BALL, right? Otherwise that specific collision handler function wouldn't get called by Chipmunk.
But in the single one place in code in the code where a shape gets that collision_type, which I posted above, I also *always* set the data field as a pointer to the ball itself a few lines later... so how come a shape with collision_type == BRK_COLLISION_TYPE__BALL can have NULL as the data field? I just don't get it. Every ball that has a shape or body gets removed from the space and freed during levels... huh?!
It's probably something silly and simple (since it doesn't occur in single player, it seems like it *has* to be a mistake on my part) but I double checked all the obvious places (and the game is still very simple, so there aren't many places to check), plus Chipmunk 5.3 is not even a day old so maybe there's something weird in the removal/freeing of shapes. Nah, it's likely me, who am I kidding
Is there a way to get all bodies and/or shapes in a space, so I can draw them and get a better picture of what is going on? Or any ideas what could cause this?