Game Development Reference
In-Depth Information
Avoiding the “Physics Space Locked” Error
Wait, did I just say “crash”? Unfortunately so:
Aborting due to Chipmunk error: You cannot manually reindex
objects while the space is locked. Wait until the current
query or step is complete.
Failed condition: !space->locked
This error is representative of a known issue with most physics engines: during collision
events, you can't modify certain aspects of the physics world (known as
space
in Chip-
munk). In this instance, playing the animation will change the node's rotation, and thus
the rotation of the node's physics body. Chipmunk doesn't like this because the physics
world (space) is
locked
, meaning the bodies in it are currently processed and need to be in
a coherent state where only the physics engine itself is allowed to make changes.
Consider where playing the animation came from: a
Trigger
instance sent the
didTriggerWithNode:
message, which in turn had its
triggerActivatedBy:
method run by the
GameScene.m
collision callback method
ccPhysicsColli-
sionBegin:player:trigger
.
Fortunately, there's a quick and simple fix for such issues. It's so simple you can try this
whenever you merely suspect such a
u can't touch this
issue. I'm terribly sorry about the
earworm.
Update the
didTriggerWithNode:
method in
PlayTimelineWhenTriggered.m
as shown in
Listing 5-17
.
Listing 5-17
.
Fixing the Chipmunk space
locked error
[self scheduleBlock:^(CCTimer *timer) {
[self.animationManager
runAnimationsForSequenceNamed:_timelineName];
} delay:0.0];
Scheduling a block with a 0 delay defers executing the contents of the block until the next
time the Cocos2D scheduler runs scheduled blocks. At the latest, this will run in the next
frame.
Search WWH ::
Custom Search