Sprite Kit iOS 7.1 在 removeFromParent 上崩溃 [英] Sprite Kit iOS 7.1 crash on removeFromParent

查看:27
本文介绍了Sprite Kit iOS 7.1 在 removeFromParent 上崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将 iPad Air 更新到 7.1,将 Xcode 更新到 5.1.Xcode 想将我的项目更新为推荐的设置,我同意了.

I have updated iPad Air to 7.1 and Xcode to 5.1. Xcode wanted to update my project to recommended settings, I agreed.

之后,当我从父节点中删除节点时,我的游戏开始在几个地方崩溃.

After that my game began crashing in a couple of places when I remove node from parent.

这对我来说是一个惊喜——更新前没有交叉.我恢复了我的项目并发现了 Xcode 对它做了什么——只改变了 Architectures 字符串:

That was a surprise for me — there were no crossings before the update. I restored my project and found out what Xcode does to it — only changes Architectures string:

之前:

之后:

在旧版本中没有崩溃.如果我在新版本中删除 arm64 支持,则不会发生崩溃.在模拟器中新旧版本都没有崩溃.

In the old version there are no crashes. There are no crashes if I remove arm64 support in new version. In the simulator there are no crashes in both new and old versions.

我应该在代码中注意哪些地方?

Where should I pay attention in my code?

代码栈:

SpriteKit`SKCSprite::removeSubsprite(SKCSprite*):
0x1859442cc:  stp    fp, lr, [sp, #-16]!
0x1859442d0:  add    fp, sp, 0
0x1859442d4:  stp    x20, x19, [sp, #-16]!
0x1859442d8:  sub    sp, sp, #16
0x1859442dc:  mov    x19, x0
0x1859442e0:  str    x1, [sp, #8]
0x1859442e4:  add    x20, sp, 8
0x1859442e8:  add    x0, x19, 544
0x1859442ec:  mov    x1, x20
0x1859442f0:  bl     0x18594872c               ; unsigned long std::__1::__tree<SKCSprite*, std::__1::less<SKCSprite*>, std::__1::allocator<SKCSprite*> >::__erase_unique<SKCSprite*>(SKCSprite* const&)
0x1859442f4:  add    x0, x19, 464
0x1859442f8:  mov    x1, x20
0x1859442fc:  bl     0x185948218               ; std::__1::list<SKCSprite*, std::__1::allocator<SKCSprite*> >::remove(SKCSprite* const&)
0x185944300:  ldr    x20, [sp, 1]
0x185944304:  ldrb   w8, [x20, #18]
0x185944308:  ldrh   w9, [x20, #16]
0x18594430c:  orr    w8, w9, w8, lsl #16
0x185944310:  tbnz   w8, #1, 0x185944324       ; SKCSprite::removeSubsprite(SKCSprite*) + 88
0x185944314:  ldr    x9, [x20, 61]
0x185944318:  ldr    x9, [x9, 2]
0x18594431c:  cbnz   x9, 0x185944324           ; SKCSprite::removeSubsprite(SKCSprite*) + 88
0x185944320:  tbz    w8, #8, 0x185944330       ; SKCSprite::removeSubsprite(SKCSprite*) + 100
0x185944324:  mov    x0, x19
0x185944328:  mov    x1, x20
0x18594432c:  bl     0x18594828c               ; SKCSprite::removeFromOffscreenList(SKCSprite*)
0x185944330:  str    xzr, [x20, #392]
0x185944334:  ldr    x8, [x20, 0]
0x185944338:  ldr    x8, [x8, 10]
0x18594433c:  mov    x0, x20
0x185944340:  blr    x8
0x185944344:  ldrh   w8, [x19, #20]
0x185944348:  orr    w9, w8, #0x40
0x18594434c:  strh   w9, [x19, #20]
0x185944350:  ldr    x8, [x19, 49]
0x185944354:  cbz    x8, 0x185944388           ; SKCSprite::removeSubsprite(SKCSprite*) + 188
0x185944358:  add    x9, x19, 392
0x18594435c:  ldrh   w10, [x8, #20]
0x185944360:  orr    w10, w10, #0x40
0x185944364:  strh   w10, [x8, #20]
0x185944368:  ldr    x8, [x9, 0]
0x18594436c:  add    x9, x8, 392
0x185944370:  ldrh   w10, [x8, #20]
0x185944374:  orr    w10, w10, #0x40
0x185944378:  strh   w10, [x8, #20]
0x18594437c:  ldr    x8, [x8, 49]
0x185944380:  cbnz   x8, 0x18594435c           ; SKCSprite::removeSubsprite(SKCSprite*) + 144

0x185944384:  ldrh   w9, [x19, #20]  EXC_BAD_ACCESS here.

0x185944388:  orr    w8, w9, #0x2
0x18594438c:  strh   w8, [x19, #20]
0x185944390:  b      0x185944398               ; SKCSprite::removeSubsprite(SKCSprite*) + 204
0x185944394:  ldrh   w8, [x19, #20]
0x185944398:  tbnz   w8, #7, 0x1859443ac       ; SKCSprite::removeSubsprite(SKCSprite*) + 224
0x18594439c:  orr    w8, w8, #0x80
0x1859443a0:  strh   w8, [x19, #20]
0x1859443a4:  ldr    x19, [x19, 49]
0x1859443a8:  cbnz   x19, 0x185944394          ; SKCSprite::removeSubsprite(SKCSprite*) + 200
0x1859443ac:  sub    sp, fp, #16
0x1859443b0:  ldp    x20, x19, [sp], #16
0x1859443b4:  ldp    fp, lr, [sp], #16
0x1859443b8:  ret    lr

更新:新信息:

我的错误:

堆栈:

我发现不对劲了.我要删除的节点由两个 SKSpriteNode(我的精灵图像及其阴影)和一个 SKShapeNode(一条细黑绳)组成.我尝试用 SKSpriteNode 绳索替换我的 SKShapeNode 绳索,但我成功了 - 问题消失了.

I found out something wrong. My node I want to remove consists of two SKSpriteNodes (my sprite image and its shadow) and one SKShapeNode (a thin black rope). I tried to replace my SKShapeNode rope with a SKSpriteNode rope and I got success — problem gone.

从父节点中删除我的节点的代码:

Code to remove my node from parent:

SKAction *moveCloud = [SKAction moveToX:destinationX duration:moveDuration];
[cloud runAction:moveCloud completion:^{
    [cloud removeFromParent];
}];

向我的节点添加 SKShapeNode 绳索的代码:

Code to add a SKShapeNode rope to my node:

- (void)addRopeToCloud:(SKNode *)cloud
{
    CGFloat maxY = self.scene.size.height;
    CGFloat length = maxY - [self.scene convertPoint:cloud.position fromNode:cloud.parent].y;

    CGMutablePathRef path = CGPathCreateMutable();
    CGPathMoveToPoint(path, NULL, 0, 0);
    CGPathAddLineToPoint(path, NULL, 0, length);

    SKShapeNode *rope = [[SKShapeNode alloc] init];
    rope.path = path;
    rope.strokeColor = [UIColor blackColor];
    rope.lineWidth = 0.1;
    rope.antialiased = YES;
    rope.zPosition = -0.01;

    CGFloat threadScale = 1 / cloud.xScale;

    rope.xScale = threadScale;
    rope.yScale = threadScale;

    [cloud addChild:rope];
    CGPathRelease(path);
}

向我的节点添加 SKSpriteNode 绳索的代码,解决了问题:

Code to add a SKSpriteNode rope to my node, that resolves the problem:

- (void)addRopeToCloud:(SKNode *)cloud
{
    CGFloat maxY = self.scene.size.height;
    CGFloat length = maxY - [self.scene convertPoint:cloud.position fromNode:cloud.parent].y;

    CGSize ropeSize = CGSizeMake(1.5, length);
    SKSpriteNode *rope = [SKSpriteNode spriteNodeWithColor:[SKColor blackColor] size:ropeSize];
    rope.anchorPoint = CGPointMake(0.5, 0);

    CGFloat ropeScale = 1 / cloud.xScale;
    rope.xScale = ropeScale;
    rope.yScale = ropeScale;

    rope.zPosition = -0.01;

    [cloud addChild:rope];
}

看起来我的 SKShapeNode 添加代码有问题,但我不明白到底是什么.

It looks like something wrong in my SKShapeNode adding code, but I can't understand what exactly is.

推荐答案

当 SKShapeNode 的父级从 iOS 7.1 中的超级视图中删除时,我也崩溃了

I also crash with SKShapeNode when its parent remove from superview in iOS 7.1

我的解决方法是将 SKShapeNode 属性设置为 nil,然后再从父级中删除

My work around is set SKShapeNode property to nil before it remove from parent

这篇关于Sprite Kit iOS 7.1 在 removeFromParent 上崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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