I'm trying to load and initialize my scene on a background thread so that it doesn't pause for 4 seconds while it loads. It works just fine with one exception: I can't get SKPhysicsJointPin -addJoint to work - it crashes every time, but only if it's called while on the thread.
The joint is setup like so:
SKPhysicsJointPin* pin =[SKPhysicsJointPin jointWithBodyA:base.physicsBody bodyB:lever.physicsBody anchor:pt];
[gameScene.physicsWorld addJoint:pin]; // this crashes on a thread!
I'm doing the background loading like so:
gSceneBeingLoaded = self; // keep a strong ref while loading so that we don't release the object prematurely
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void)
{
/* LOAD SCENE ON BACKGROUND THREAD */
[gSceneBeingLoaded loadSceneData];
/* SHOW SCENE ON MAIN THREAD */
dispatch_async(dispatch_get_main_queue(), ^(void)
{
[gSceneBeingLoaded presentScene];
gSceneBeingLoaded = nil; // release the extra reference
});
});
Like I say, everything works great except for that one call which will crash every time, but only when on a thread.
This might solve your problem for addJoint: