I'm asking my "space" to remove a body, using:
Code: Select all
if ( [space.bodies containsObject:self.body] ) {
[space addPostStepRemoval:self.body];
}
[space addPostStepRemoval:self.shape];
First stack is
0x000b5cae <+0042> mov r0, r6
calls to
cpSpaceEachBody
cpSpaceUnlock
cpHashSetEach
cpSpacePostStepCallbackSetlter
postStepPerform
NSObject performSelector
ChipmunkSpace remove:
ChipmunkSpace removeFromSpace:
ChipmunkSpace removeShape:
cpSpaceRemoveShape
cpBBTreeRemove
SubtreeRemove
The main curiosity is, why on earth is querying bodies leading to a remove? Aha, but if you look at my code, you'll see that I am in fact removing a body and a shape, in a postStepRemoval.
Therefore, my theory is that the callback is mutating the array while that array is being queried in a close subsequent call (the code I posted above can get called many times in rapid succession).
I am going to work on my end to see if I can't lock the code, but I think the underlying issue is that accessing bodies is not safe when a postStepRemoval has been queued but not completed. That strikes me as a bug. Apologies if I am wrong.