我有一个简单的类func,可以在很多不同的场合添加SKEmitterNode。
发生异常时我无法重现步骤。它很少发生并且相当随机。我可以在没有错误的情况下调用此方法500次,或者在某些情况下,在1次或2次调用之后可能会发生错误等等。
问题/异常行是:
根?.addChild(火花)
以下是方法和堆栈跟踪。我不知道如何调试这个。我尝试了许多不同的事情但没有成功。
有什么想法吗?
class func setSimpleSparksEffect(root:SKNode?, color:UIColor, position:CGPoint)
{
if CGPointEqualToPoint(position, CGPointZero)
{
return
}
let sparks = SKEmitterNode(fileNamed: "SimpleSparks")
sparks.alpha = GameObjectsDefaultAlpha
sparks.particleColorSequence = nil
sparks.particleColorBlendFactor = 1.0
sparks.particleColor = color
sparks.position = position
sparks.zPosition = SparksElementsZPosition
root?.addChild(sparks)
sparks.runAction(SKAction.waitForDuration(NSTimeInterval(EmmiterSimpleShortDuration)), completion: { () -> Void in
sparks.runAction(SKAction.fadeOutWithDuration(NSTimeInterval(FactorSparksFadeOutDuration)), completion: { () -> Void in
sparks.removeAllActions()
sparks.removeAllChildren()
sparks.removeFromParent()
})
})
}
堆栈跟踪:
Thread : Crashed: com.apple.main-thread
0 libc++abi.dylib 0x0000000199944ce4 __dynamic_cast + 52
1 SpriteKit 0x000000018ab63f58 __15-[SKNode scene]_block_invoke + 60
2 SpriteKit 0x000000018ab63f58 __15-[SKNode scene]_block_invoke + 60
3 SpriteKit 0x000000018ab28038 SKCNode::walkUp(void (SKCNode*, bool*) block_pointer, bool) + 76
4 SpriteKit 0x000000018ab63eac -[SKNode scene] + 132
5 SpriteKit 0x000000018ab643ac -[SKNode insertChild:atIndex:] + 356
6 SpriteKit 0x000000018ab64224 -[SKNode addChild:] + 76
7 DodgeMaster 0x00000001000f1d80 static DodgieCommon.setSimpleSparksEffect(SKNode?, color : UIColor, position : CGPoint) -> () (DodgieCommon.swift:275)
8 DodgeMaster 0x00000001000d2bc4 GameLevel.(gameLogicGoalerHitmeContact(GameLevel) -> (NSNotification) -> ()).(closure #1) (GameLevel.swift:502)
9 DodgeMaster 0x0000000100125018 static Helper.(runAsyncOnMain(Helper.Type) -> (() -> ()) -> ()).(closure #1) (Helper.swift:270)
10 DodgeMaster 0x00000001000b41c4 thunk (Pointoser.swift)
11 libdispatch.dylib 0x000000019aa917b0 _dispatch_call_block_and_release + 24
12 libdispatch.dylib 0x000000019aa91770 _dispatch_client_callout + 16
13 libdispatch.dylib 0x000000019aa96e20 _dispatch_main_queue_callback_4CF + 1844
14 CoreFoundation 0x000000018574c258 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12
15 CoreFoundation 0x000000018574a0c0 __CFRunLoopRun + 1628
16 CoreFoundation 0x0000000185678dc0 CFRunLoopRunSpecific + 384
17 GraphicsServices 0x00000001907cc088 GSEventRunModal + 180
18 UIKit 0x000000018ad52f60 UIApplicationMain + 204
19 DodgeMaster 0x000000010011de24 main (AppDelegate.swift:22)
20 libdyld.dylib 0x000000019aac28b8 start + 4
答案 0 :(得分:1)
另一个人在这里有一个similar problem我认为你也可能遇到过......我已经为你的帖子量身定做了我的回复。
let sparksFile: String = NSBundle.mainBundle().pathForResource("SimpleSparks", ofType: "sks")!
let sparks = NSKeyedUnarchiver.unarchiveObjectWithFile(explosionFile) as! SKEmitterNode
sparks.alpha = GameObjectsDefaultAlpha
sparks.particleColorSequence = nil
sparks.particleColorBlendFactor = 1.0
sparks.particleColor = color
sparks.position = position
sparks.zPosition = SparksElementsZPosition
self.root?.addChild(sparks)