Skip to content

Commit

Permalink
Merge pull request #98 from panter/fix-crash-when-using-hittest
Browse files Browse the repository at this point in the history
fix occasional crash when using hittest
  • Loading branch information
macrozone authored Oct 25, 2017
2 parents 66b372a + 239a57f commit be3bc7d
Showing 1 changed file with 24 additions and 31 deletions.
55 changes: 24 additions & 31 deletions ios/RCTARKitNodes.m
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ - (NSDictionary *)getSceneObjectsHitResult:(const CGPoint)tapPoint {
SCNHitTestRootNodeKey: self.localOrigin,
SCNHitTestSortResultsKey: @(YES)
};
NSArray<SCNHitTestResult *> *results = [_arView hitTest:tapPoint options:options];
NSArray<SCNHitTestResult *> *results = [_arView hitTest:tapPoint options:options];
NSMutableArray * resultsMapped = [self mapHitResultsWithSceneResults:results];
NSDictionary *result = getSceneObjectHitResult(resultsMapped, tapPoint);
return result;
Expand All @@ -156,39 +156,32 @@ - (NSDictionary *)getSceneObjectsHitResult:(const CGPoint)tapPoint {
- (NSMutableArray *) mapHitResultsWithSceneResults: (NSArray<SCNHitTestResult *> *)results {

NSMutableArray *resultsMapped = [NSMutableArray arrayWithCapacity:[results count]];

[results enumerateObjectsUsingBlock:^(id obj, NSUInteger index, BOOL *stop) {
SCNHitTestResult *result = (SCNHitTestResult *) obj;
SCNNode * node = result.node;
NSArray *keys = [self.nodes allKeysForObject: node];
if([keys count]) {

NSString * firstKey = [keys firstObject];

SCNVector3 point = result.worldCoordinates;
SCNVector3 normal = result.worldNormal;

float distance = [self getCameraDistanceToPoint:point];
[resultsMapped addObject:(@{
@"id": firstKey,
@"distance": @(distance),
@"point": @{
@"x": @(point.x),
@"y": @(point.y),
@"z": @(point.z)
},
@"normal": @{
@"x": @(normal.x),
@"y": @(normal.y),
@"z": @(normal.z)

}
} )];
} else {
NSLog(@"no key found for node %@", node);
NSLog(@"for results %@", results);
NSLog(@"all nodes %@", self.nodes);
NSLog(@"origin %@", self.localOrigin);
}


SCNVector3 point = result.worldCoordinates;
SCNVector3 normal = result.worldNormal;
NSString * nodeId = node.name;
float distance = [self getCameraDistanceToPoint:point];
[resultsMapped addObject:(@{
@"id": nodeId,
@"distance": @(distance),
@"point": @{
@"x": @(point.x),
@"y": @(point.y),
@"z": @(point.z)
},
@"normal": @{
@"x": @(normal.x),
@"y": @(normal.y),
@"z": @(normal.z)

}
} )];


}];
return resultsMapped;
Expand Down

0 comments on commit be3bc7d

Please sign in to comment.