iOS 8 SpriteKit在添加或删除阻止/操作中的子项时崩溃

时间:2014-09-19 10:54:15

标签: objective-c sprite-kit ios8

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

 [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操作替换为:

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

这似乎解决了这个问题。

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

崩溃日志:

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测试中它永远不会崩溃)

1 个答案:

答案 0 :(得分:3)

我在iOs8中遇到了枚举问题:

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

dispatch_async也有帮助。

并注意所有:没有发生崩溃 - 大约需要0.5秒,而且代码可能会被执行。