gpt4 book ai didi

ios - SKNode addChild 上的奇怪随机崩溃

转载 作者:可可西里 更新时间:2023-11-01 02:19:02 24 4
gpt4 key购买 nike

我有一个简单的类函数,用于在许多不同的场合添加 SKEmitterNode。

发生异常时我无法重现步骤。它很少发生而且很随机。我可以调用此方法 500 次而不会出错,或者在某些情况下,调用 1 次或 2 次后可能会发生错误,等等。

问题/异常行是:

root?.addChild(sparks)

下面是方法和堆栈跟踪。我不知道如何调试它。我尝试过很多不同的东西但没有成功。

有什么想法吗?

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

最佳答案

这里的另一个人有一个 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)

关于ios - SKNode addChild 上的奇怪随机崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32693021/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com