Space Lock Race Condition

Official forum for the Chipmunk2D Physics Library.

Space Lock Race Condition

Postby pkclsoft » Tue Jan 20, 2015 7:46 am

I have some code where I queue a sound effect with a block to be executed at the end of that effect. The block is executed in a different thread to that of the main thread where chipmunk is being updated. In my block I explicitly call cpSpaceIsLocked() and either add a post step callback if it returns YES, or do the action the post step would do if not.

What I'm seeing is that intermittently, cpSpaceIsLocked() is returning NO, but the app still crashes with a space->locked message because presumably the main thread has started chipmunk.update() just after the sound threads call to cpSpaceIsLocked(). The code being actioned by the sound completion block is basically executing code that indirectly triggers a dealloc which removes a sprite and it's associated body/shapes from the space.

Code: Select all
if (cpSpaceIsLocked(cpBodyGetSpace(self.body))) {
  cpSpaceAddPostStepCallback(cpBodyGetSpace(self.body), punchPopFunc, @"punchPopFunc", self);
} else {
  [self popForValue:0];
}


Apart from removing this execution of a block by the sound thread upon completion of the sound effect, I'm wondering if there is an established mechanism for handling this sort of thing.
pkclsoft
 
Posts: 5
Joined: Mon Jun 11, 2012 12:10 am

Return to Chipmunk2D Physics

Who is online

Users browsing this forum: No registered users and 1 guest