cpShapeSetBody unsafe

Discuss any Chipmunk bugs here.

cpShapeSetBody unsafe

Postby scribbleink » 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):

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
}


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):
Code: Select all
static inline cpBool
cpShapeActive(cpShape *shape)
{
   return shape->prev || shape->body->shapeList == shape;
}


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?
Code: Select all
static inline cpBool
cpShapeActive(cpShape *shape)
{
   return shape->prev || (shape->body && shape->body->shapeList == shape);
}


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
scribbleink
 
Posts: 2
Joined: Mon Feb 27, 2012 8:20 pm

Re: cpShapeSetBody unsafe

Postby slembcke » Mon Apr 09, 2012 8:38 am

Hmm. It looks like I might have fixed that in the current Git code. What version are you running. I remember something about that coming up a few months ago, but not what exactly. Somebody was doing something with serialization stuff maybe? Anyway, cpSpaceAddBody() looks like it should be safe anyway.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
slembcke
Site Admin
 
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm

Re: cpShapeSetBody unsafe

Postby scribbleink » Tue Apr 10, 2012 4:57 am

slembcke wrote: It looks like I might have fixed that in the current Git code.

Yeah, it's fixed according to this. Sorry I didn't test the latest one like I should have (since we froze a previous version for our development purposes).

slembcke wrote:What version are you running.

It was 6.0.2.

slembcke wrote:I remember something about that coming up a few months ago, but not what exactly. Somebody was doing something with serialization stuff maybe?

I couldn't find anything in the forums at the time I posted this. After looking on the Git repo, this would be marked a duplicate of #2.

Thanks for your help.
scribbleink
 
Posts: 2
Joined: Mon Feb 27, 2012 8:20 pm


Return to Bugs

Who is online

Users browsing this forum: No registered users and 1 guest