ios – 什么是Sprite Kit中的SKSpinLockSync以及如何解决它

我收到一个带有以下堆栈跟踪的错误报告,我不知道问题是什么.我已经看到这样的建议,这可能是由于在纹理图集中有一个发射器的图像,或者是在添加的同一个运行循环中移除了一个发射器,但我认为这些都不会发生.这是一个零星的问题,我无法再创造它.我只在bug报告中看到它.我很乐意帮忙.
0    libsystem_platform.dylib    OsspinLockLock + 1
1    SpriteKit   SKSpinLockSync(int*,void ()() block_pointer) + 92
2    SpriteKit   -[SKTexture loadImageData] + 300
3    SpriteKit   -[SKTexture size] + 42
4    SpriteKit   SKCEmitterSprite::update(double) + 3136
5    SpriteKit   SKCSprite::update(double) + 354
6    SpriteKit   SKCSprite::update(double) + 354
7    SpriteKit   -[SKScene _update:] + 174
8    SpriteKit   -[SKView(Private) _update:] + 324
9    SpriteKit   -[SKView renderCallback:] + 820
10   SpriteKit   __29-[SKView setUpRenderCallback]_block_invoke + 130
11   SpriteKit   -[SKdisplayLink _callbackForNextFrame:] + 254
12   QuartzCore  CA::display::displayLinkItem::dispatch() + 98
13   QuartzCore  CA::display::displayLink::dispatch_items(unsigned long long,unsigned long long,unsigned long long) + 344
14   IOMobileFramebuffer     IOMobileFramebufferVsyncNotifyFunc + 104
15   IOKit   IOdispatchCalloutFromCFMessage + 248
16 ...   CoreFoundation  __CFMachPortPerform + 136
17   CoreFoundation  __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 34
18   CoreFoundation  __CFRunLoopDoSource1 + 346
19   CoreFoundation  __CFRunLoopRun + 1406
20   CoreFoundation  CFRunLoopRunSpecific + 524
21   CoreFoundation  CFRunLoopRunInMode + 106
22   GraphicsServices    GSEventRunModal + 138
23   UIKit   UIApplicationMain + 1136
24   myApplication  main.m line 16  main

编辑:我现在意识到我在几种不同的情况下得到SKSpinLockSync问题,并不总是与发射器有关.我认为,我经常使用发射器看到它的唯一原因是因为这是应用程序中图像加载的狮子份额所以它只是统计上最可能的.堆栈跟踪的前四行始终相同.所以,包括[SKTexture Size].

解决方法

我有同样的问题,当我打电话时,我发现了
Nsstring *p = [[NSBundle mainBundle] pathForResource:name ofType:@"sks"];  
SKEmitterNode *e = [NSKeyedUnarchiver unarchiveObjectWithFile:p];

很多时候,它将使用相同的崩溃日志随机崩溃应用程序

SKSpinLockSync(int*,void ()() block_pointer) + 36  
-[SKTexture loadImageData] + 252  
-[SKTexture size] + 44  
SKCEmitterSprite::update(double) + 2928

我认为这是Sprite Kit的问题,希望Apple能尽快解决这个问题

我的解决方案是:不要每次都调用unarchiveObjectWithFile

unarchiveObjectWithFile可能与IO有关,如果您经常像游戏中的每一帧那样执行此操作,或者来自SKTexture缓存系统的问题在需要纹理数据并在非线程安全中调用loadImageData时出现问题,则可能会崩溃.

所以我重复使用SKEmitterNode,这是我的功能

// 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];
}

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...