I'm using the latest Chipmunk 5.0 code with Cocos2d for the iphone and I get a crash in this function randomly. It doesn't happen often but it has been happening for over a month and no matter what I do, I can never seem to fix it. I did have it crash once with the debugger up and the pointer for "elt" was bad, it was a small value like 0x343. So it is crashing from a memory access violation but how did "elt" get bad in the first place? "elt" is coming from space->activeShapes->handleSet->table->[1..x]next->elt. Any ideas what I should focus on in my code? Could it be caused by not removing shapes/bodies correctly from activeShapes? I know this might be a very broad question but my hope is someone else has run into the same issue before and remembers how they fixed it. I call cpSpaceStep 120 times a second if that info helps.
Here's the callstack and snippets of the code that match the line number:
Exception Type: EXC_BAD_ACCESS (SIGBUS)
Exception Codes: KERN_PROTECTION_FAILURE at 0x00000004
Thread 0 Crashed:
0 Program 0x00156be8 handleQueryRehashHelper (cpSpaceHash.c:431)
1 Program 0x00153fcc cpHashSetEach (cpHashSet.c:198)
2 Program 0x00156684 cpSpaceHashQueryRehash (cpSpaceHash.c:472)
3 Program 0x001556fc cpSpaceStep (cpSpace.c:659)
Ok, I'll try to handle this better by using cpSpaceAddPostStepCallback to remove my shapes and bodies from collision callbacks. I already have a function to collect shapes and free them at a later time though but it looks like that isn't enough.
Yup. The post step callbacks were added after much complaining (from me too!) that you couldn't remove objects inside of callbacks. As well as a lot of crashes due to trying. It's perhaps not quite as elegant as just removing it directly, but it works pretty well and helps solve the issue of attempting to remove objects from more than one callback.
I should probably add an assertion that runs in debug mode to check that.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/