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.
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /reply/detail/tangjaffa
-
YouTube API 不能在 iOS (iPhone/iPad) 工作,但在桌面浏览器工作正常?
it1352 07-30 -
iPhone,一张图像叠加到另一张图像上以创建要保存的新图像?(水印)
it1352 07-17 -
保持在后台运行的 iPhone 应用程序完全可操作
it1352 07-25 -
使用 iPhone 进行移动设备管理
it1352 07-23 -
在android同时打开手电筒和前置摄像头
it1352 09-28 -
扫描 NFC 标签时是否可以启动应用程序?
it1352 08-02 -
检查邮件是否发送成功
it1352 07-25 -
Android微调工具-删除当前选择
it1352 06-20 -
Android App 和三星 Galaxy S4 不兼容
it1352 07-20 -
希伯来语的空格句子标记化错误
it1352 06-22