NSValue SCNVector3崩溃

时间:2015-04-22 13:05:40

标签: objective-c dictionary scenekit nsvalue

我从SCNVector3结构创建NSValue对象。

 NSValue *value = [NSValue valueWithSCNVector3:vector]

之后我将它们添加到字典中。每当我尝试从字典应用程序崩溃中访问值时,但仅在发布模式下。琐碎的东西看起来还不错。

当我用自定义对象替换NSValue时,一切正常。 (完全相同的代码)

(我用xxx替换了项目名称和方法调用)

+ (NSDictionary *)methodA:(NSArray *)nodes {

    NSMutableDictionary *nodeBounds = [NSMutableDictionary dictionary];
    for (SCNNode *node in nodes) {    
         SCNVector3 vector = [node boundingBoxMax];
         NSValue *value = [NSValue valueWithSCNVector3:vector];
         nodeBounds[node.name] = value;
    }

    NSArray *array = [self sortDictionaryKeysWithVector3:nodeBounds];

    return [nodeBounds copy];
}

 + (NSArray *)sortDictionaryKeysWithVector3:(NSDictionary *)vectors {

    NSArray *keysSortedByValue = [vectors keysSortedByValueUsingComparator:^NSComparisonResult(NSValue *vectorValue1, NSValue *vectorValue2) {

    SCNVector3 vector1 = [vectorValue1 SCNVector3Value];
    SCNVector3 vector2 = [vectorValue2 SCNVector3Value];
    return (NSComparisonResult)NSOrderedSame;
 }];

    return keysSortedByValue;
}

堆栈追踪:

* thread #1: tid = 0x814ff, 0x2fe336b8 libobjc.A.dylib`objc_retain + 8, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0xb39cefb2)
    frame #0: 0x2fe336b8 libobjc.A.dylib`objc_retain + 8
    frame #1: 0x000795c6 xxx`__46+[xxx sortDictionaryKeysWithVector3:]_block_invoke(.block_descriptor=<unavailable>, vectorValue1=<unavailable>, vectorValue2=<unavailable>) + 22 at xxx.m:138

frame #2: 0x21b336e6 CoreFoundation`__CFSimpleMergeSort + 290
    frame #3: 0x21b3365a CoreFoundation`__CFSimpleMergeSort + 150
    frame #4: 0x21b3365a CoreFoundation`__CFSimpleMergeSort + 150
    frame #5: 0x21b3365a CoreFoundation`__CFSimpleMergeSort + 150
    frame #6: 0x21b3365a CoreFoundation`__CFSimpleMergeSort + 150
    frame #7: 0x21b3365a CoreFoundation`__CFSimpleMergeSort + 150
    frame #8: 0x21a82e0a CoreFoundation`CFSortIndexes + 410
  * frame #9: 0x21aea2d6 CoreFoundation`-[NSDictionary keysSortedByValueWithOptions:usingComparator:] + 366
    frame #10: 0x00079528 xxx`+[xxx methodA:](self=<unavailable>, _cmd=<unavailable>, nodes=<unavailable>) + 504 at xxx:130

0 个答案:

没有答案