SpriteKit convertPoint:toNode:抛出EXC_BAD_ACCESS错误

时间:2014-04-19 17:37:59

标签: objective-c memory sprite-kit exc-bad-access

我在函数(ARC)中有以下代码提取:

-(CGFloat)getRotationAngleFromJoint:(BAJoint*)from_joint toJoint:(BAJoint*)to_joint {
    // Here we basically have a node graph where joints are connected by bones.
    // In this case we have these connections: from_joint -> from_bone -> from_joint2
    //
    // BAJoint and BABone both derived classes of SKShapeNode

    __weak BABone *from_bone = (BABone*)[from_joint.children objectAtIndex:0];
    __weak BAJoint *from_joint2 = (BAJoint*)[from_bone.children objectAtIndex:0];

    CGPoint k = CGPointMake(0, 0);
    CGPoint p1 = [from_joint2 convertPoint:k toNode:from_joint.parent];

BAJoint因此宣布:

@interface BAJoint : SKShapeNode <NSCoding, NSCopying>

@property BOOL rootJoint;

-(void)setRootJoint;
-(void)select;
-(void)deselect;

@end

from_joint2 from_joint from_joint.parent 都是非零弱指针,但在调用 convertPoint:toNode:

时出现EXC_BAD_ACCESS错误

我已通过记录 位置 iVar确认弱指针指向有效内存,例如 from_joint.position ,并在这些情况下记录合理的值。至少我假定一个合理的值意味着指针指向内存中的有效位置。

启用僵尸并不会显示任何内容,启用异常断点甚至无法捕捉到这一点。

convertPoint:toNode:的任何想法可能会引发EXC_BAD_ACCESS错误?在这种特殊情况下,可能会导致此错误的原因是什么?

我真的很感激任何帮助,因为我花了很长时间看着它。我对Objective-C很新。

更新

在阅读了StackOverflow上的一些帖子后,我有一种偷偷摸摸的怀疑,即SKShapeNode非常容易受到攻击。我通过使用SKNode *实例复制子图并将convertPoint:toNode:应用于SKNodes而不是SKShapeNodes解决了我的问题。

此外,SKShapeNode似乎不断泄漏内存,此处的其他帖子也表示相同。

0 个答案:

没有答案