Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c NSValue SCONVERTOR3崩溃_Objective C_Dictionary_Scenekit_Nsvalue - Fatal编程技术网

Objective c NSValue SCONVERTOR3崩溃

Objective c NSValue SCONVERTOR3崩溃,objective-c,dictionary,scenekit,nsvalue,Objective C,Dictionary,Scenekit,Nsvalue,我从SCInvector3结构创建NSValue对象 NSValue *value = [NSValue valueWithSCNVector3:vector] 然后我把它们加入字典。每当我试图访问字典中的值时,应用程序就会崩溃,但只能在发布模式下。琐碎的东西看起来没问题 当我用自定义对象替换NSValue时,一切正常。完全相同的代码 我用xxx替换了项目名称和方法调用 + (NSDictionary *)methodA:(NSArray *)nodes { NSMutableDi

我从SCInvector3结构创建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

因此,将该值放入字典并访问该值会导致崩溃?您应该显示更多代码并返回跟踪sortDictionaryKeysWithVector3方法甚至不应该编译。比较块永远不会关闭,不会返回排序结果,也没有结束方括号。我说过这里没有小错误。这是我邮寄时的纸条。已编辑。您仍然没有在该块中返回比较结果。