I had the same problem and I found that when I call
NSString *p = [[NSBundle mainBundle] pathForResource:name ofType:@"sks"]; SKEmitterNode *e = [NSKeyedUnarchiver unarchiveObjectWithFile:p];
many times, it will accidentally crash the application with the same crash log
SKSpinLockSync(int*, void ()() block_pointer) + 36 -[SKTexture loadImageData] + 252 -[SKTexture size] + 44 SKCEmitterSprite::update(double) + 2928
I think this is a problem with the Sprite Kit and I hope that Apple will fix it soon.
My solution: do not call unarchiveObjectWithFile every time
unarchiveObjectWithFile can relate to IO, and it can crash if you do it too often, like every frame in your game, or a problem arising from the SKTexture caching system has problems when it needs texture data and causes loadImageData to be safe different from threads.
So, I am reusing SKEmitterNode with a copy, here is my function
// Emitter Pool - (SKEmitterNode*)getEmitter:(NSString*)name { if(!mDictEmitter) self.mDictEmitter = [NSMutableDictionary new]; SKEmitterNode *e = [mDictEmitter objectForKey:name]; if(!e){ NSString *p = [[NSBundle mainBundle] pathForResource:name ofType:@"sks"]; e = [NSKeyedUnarchiver unarchiveObjectWithFile:p]; [mDictEmitter setObject:e forKey:name]; } return [e copy]; }
source share