cpShapeSetBody unsafe
Posted: Sun Apr 08, 2012 8:15 pm
Hi Scott,
I'm using Chipmunk 6.0.1 in C and my use case is in this particular order (forgive my short-hand syntax):
Now this should work since it follows the rules in the documentation in that I'm setting the Body of each Shape before adding it to the space.
However, I got a SIGSEGV and tracked it down to cpSpaceAddBody() calling an assertion cpShapeActive() which in the private API reads like the following around line 105 (chipmunk_private.h, 6.0.3):
When shape->body == NULL, this code terminates although the shape isn't active because it isn't attached to a body. Could you please change this to, perhaps the following?
There might be other ways to do this, and I know this isn't a typical use-case scenario, but I wanted to bring this to your notice. Keep up the good work!
Best,
Nikhil
I'm using Chipmunk 6.0.1 in C and my use case is in this particular order (forgive my short-hand syntax):
Code: Select all
{
shape[i] = cpPolyShapeNew(NULL, ...); // create multiple shapes without a body
}
body = cpSpaceAddBody(...); // create a body later
{
cpShapeSetBody(shape[i], body) // set them to be part of the same body
cpSpaceAddShape(shape[i]) // add them to the space
}
However, I got a SIGSEGV and tracked it down to cpSpaceAddBody() calling an assertion cpShapeActive() which in the private API reads like the following around line 105 (chipmunk_private.h, 6.0.3):
Code: Select all
static inline cpBool
cpShapeActive(cpShape *shape)
{
return shape->prev || shape->body->shapeList == shape;
}
Code: Select all
static inline cpBool
cpShapeActive(cpShape *shape)
{
return shape->prev || (shape->body && shape->body->shapeList == shape);
}
Best,
Nikhil