wierd behaviour in cpPolyShapeSetVerts

Discuss any Chipmunk bugs here.

wierd behaviour in cpPolyShapeSetVerts

Postby jj2010 » Sun Mar 20, 2011 5:29 am

Hi, well first of all, I know cpPolyShapeSetVerts function is in the 'unsafe' API but anycase, I have a very strange bug involving its usage and I wonder if you could maybe suggest a solution, or at least a work-around to this problem:

Basically, I have a bunch of shapes attached to a body, and these shapes use this API call to adjust the vertices in different ways, specifically, by applying an offset to them, in the 'offset' part.

This allows to create shapes that adjust their appearance, for example, a larger box that becomes smaller when shot at.

So far, everything is working fine and the simulation behaves pretty much as you would expect, but with one wierd and subtle behaviour...

I decided to use CPSegmentQueryFirst, as in the following example...

Code: Select all
cpSegmentQueryInfo info = {};
        if(cpSpaceSegmentQueryFirst(g_Space, start, end,CP_LAYER_BITMASK_ALL_OBJECTS, 0, &info))
      out_hitpoint = cpSegmentQueryHitPoint(start, end, info);      
      return (void*) info.shape->data;
   return NULL;

...To simulate an instant-hit projectile. The collision detection works fine, so long as the cpPolyShapeSetVerts function hasn't been called yet, but once this function has been called, the cpSpaceSegmentQueryFirst call no longer detects any collision with that shape. What's even more bizarre is that the physics for the shape continues to behave as normal, the only thing that doesn't work any more is the 'cpSpaceSegmentQueryFirst' function, which stops working for that shape.

Do you have any ideas why the call to cpPolyShapeSetVerts would mess up the call cpSpaceSegmentQueryFirst ? any suggestion about how to fix this problem would be welcome
Posts: 5
Joined: Thu Jun 03, 2010 12:57 am

Re: wierd behaviour in cpPolyShapeSetVerts

Postby slembcke » Sun Mar 20, 2011 2:04 pm

If you modify a shape by changing it's body's position or using one of the setter functions, it's collision detection data will be out of sync from the last cpSpaceStep(). This can lead to missed or incorrect queries until the next time that cpSpaceStep() is called. To update the collision detection data for a changed/moved shape you can call cpSpaceRehashShape(space, shape).

If you mean that after calling cpPolyShapeSetVerts() the shape is permanently unable to be queried, then I'm not quite sure what the problem would be.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
Site Admin
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm

Return to Bugs

Who is online

Users browsing this forum: No registered users and 1 guest