iOS 8 SpriteKit 在从块/动作中添加或删除孩子时崩溃 [英] iOS 8 SpriteKit crashes on adding or removing a child from block/action

查看:22
本文介绍了iOS 8 SpriteKit 在从块/动作中添加或删除孩子时崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从 iOS8 开始,我的游戏突然开始崩溃.经过一番调试,我发现游戏在以下两个地方崩溃:

As of iOS8 my game started to crash all of a sudden. After a bit of debugging I have found that the game crashes in the two following places :

 [sparkNode runAction:[SKAction sequence:@[
                                           //Some actions and finally...
                                           [SKAction removeFromParent]]]]; // Crashes here (If I remove this action no crash occurs)

还有第二名:

[rankTransitionSprite runAction:[SKAction sequence:@[[SKAction scaleTo:1.5 duration:1.0],
                                                     [SKAction runBlock:^{
    CGPoint rankPosition = _rankSprite.position;
    [_rankSprite removeFromParent];
    _rankSprite = [_spritesFactory spriteFromAtlasForImageName:[NSString stringWithFormat:@"rank%d", rank]];
    [self addChild:_rankSprite]; // Crashes here
}],
                                                     [SKAction scaleTo:0.0 duration:1.0],
                                                     [SKAction removeFromParent]]]];

在 iOS 7.1 上不会发生崩溃.它只在 iOS8 上崩溃.对于第一次崩溃,我将 removeFromParent 操作替换为:

On iOS 7.1 the crash does NOT occur. It only crashes on iOS8. For the first crash I replaced the removeFromParent action with :

[SKAction runBlock:^{
                      dispatch_async(dispatch_get_main_queue(), ^{
                           [sparkNode removeFromParent]; 
                      });
}]

这似乎解决了问题.

对于第二次崩溃,我做了同样的事情(在主线程中添加精灵)并且崩溃消失了.

For the second crash I did the same thing (Adding the sprite in the main thread) and the crash was gone.

崩溃日志:

Thread 0 Crashed:: Dispatch queue: com.apple.spritekit.renderQueue
0   SpriteKit                       0x000000010abed9fe SKCRenderer::preprocessSpriteImp(std::__1::vector<SKCRenderer::SpriteRenderInfo, std::__1::allocator<SKCRenderer::SpriteRenderInfo> >&, SKRenderQuadPool&, SKCSprite const*, _GLKMatrix4 const&, float, unsigned int&, bool) + 372
1   SpriteKit                       0x000000010abee82b SKCRenderer::preprocessSpriteImp(std::__1::vector<SKCRenderer::SpriteRenderInfo, std::__1::allocator<SKCRenderer::SpriteRenderInfo> >&, SKRenderQuadPool&, SKCSprite const*, _GLKMatrix4 const&, float, unsigned int&, bool) + 4001
2   SpriteKit                       0x000000010abee82b SKCRenderer::preprocessSpriteImp(std::__1::vector<SKCRenderer::SpriteRenderInfo, std::__1::allocator<SKCRenderer::SpriteRenderInfo> >&, SKRenderQuadPool&, SKCSprite const*, _GLKMatrix4 const&, float, unsigned int&, bool) + 4001
3   SpriteKit                       0x000000010abe7c21 SKCRenderer::preprocessAndSubmitSpriteInternal(std::__1::vector<SKCRenderer::SpriteRenderInfo const*, std::__1::allocator<SKCRenderer::SpriteRenderInfo const*> >&, std::__1::vector<SKCRenderer::SpriteRenderInfo, std::__1::allocator<SKCRenderer::SpriteRenderInfo> >&, SKRenderQuadPool&, SKCSprite const*, _GLKMatrix4 const&) + 139
4   SpriteKit                       0x000000010abeb7d1 SKCRenderer::submitScene(SKScene*, bool) + 393
5   SpriteKit                       0x000000010abeff16 SKCRenderer::renderScene(SKScene*, bool) + 86
6   SpriteKit                       0x000000010ab87542 -[SKView _renderContent] + 1027
7   libdispatch.dylib               0x000000010c974b94 _dispatch_client_callout + 8
8   libdispatch.dylib               0x000000010c9611e7 _dispatch_barrier_sync_f_invoke + 76
9   SpriteKit                       0x000000010ab870f3 -[SKView renderContent] + 89
10  SpriteKit                       0x000000010ab8415c __29-[SKView setUpRenderCallback]_block_invoke + 54
11  SpriteKit                       0x000000010abb0a54 -[SKDisplayLink _callbackForNextFrame:] + 256
12  QuartzCore                      0x000000010ecf0967 CA::Display::DisplayLinkItem::dispatch() + 37
13  QuartzCore                      0x000000010ecf082f CA::Display::DisplayLink::dispatch_items(unsigned long long, unsigned long long, unsigned long long) + 315
14  CoreFoundation                  0x000000010b39e4d4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 20
15  CoreFoundation                  0x000000010b39e095 __CFRunLoopDoTimer + 1045
16  CoreFoundation                  0x000000010b3613cd __CFRunLoopRun + 1901
17  CoreFoundation                  0x000000010b3609f6 CFRunLoopRunSpecific + 470
18  GraphicsServices                0x000000010d41d9f0 GSEventRunModal + 161
19  UIKit                           0x00000001098cb990 UIApplicationMain + 1282

我的问题是为什么它只在 iOS8 上崩溃?(在许多 iOS 7.1 测试中它从未崩溃过)

And my question is why does it crash only on iOS8? (on many iOS 7.1 tests it never crashed)

推荐答案

在iOs8中遇到一个枚举问题:

I faced with a problem in enumerate in iOs8:

[supers enumerateChildNodesWithName:@"super3" usingBlock:^(SKNode *node, BOOL *stop) {
 ....
            [supers addChild:super3counter]; //crash here
}]; 

dispatch_async 也有帮助.

dispatch_async helped too.

请注意:崩溃不会立即发生 - 大约需要 0.5 秒,甚至可以执行前后代码.

And note all: crash not occured immidiatly - it takes about 0.5 sec, and code befro and after can be even executed.

这篇关于iOS 8 SpriteKit 在从块/动作中添加或删除孩子时崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆