Skip to content

Commit 14cb513

Browse files
committed
Add logs to parseReferenceImage to simplify error handling
1 parent e855569 commit 14cb513

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

ios/Classes/Utils/ReferenceImagesParser.swift

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,24 @@ func parseReferenceImagesSet(_ images: [[String: Any]]) -> Set<ARReferenceImage>
77
}
88

99
func parseReferenceImage(_ dict: [String: Any]) -> ARReferenceImage? {
10-
if let physicalWidth = dict["physicalWidth"] as? Double,
11-
let name = dict["name"] as? String,
12-
let image = getImageByName(name),
13-
let cgImage = image.cgImage
14-
{
15-
let referenceImage = ARReferenceImage(cgImage, orientation: CGImagePropertyOrientation.up, physicalWidth: CGFloat(physicalWidth))
16-
referenceImage.name = name
17-
return referenceImage
10+
guard let physicalWidth = dict["physicalWidth"] as? Double else {
11+
debugPrint("ARKitReferenceImage: missing or invalid physicalWidth: \(dict)")
12+
return nil
1813
}
19-
return nil
14+
guard let name = dict["name"] as? String else {
15+
debugPrint("ARKitReferenceImage: missing or invalid name: \(dict)")
16+
return nil
17+
}
18+
guard let image = getImageByName(name) else {
19+
debugPrint("ARKitReferenceImage: failed to load image for name: \(name)")
20+
return nil
21+
}
22+
guard let cgImage = image.cgImage else {
23+
debugPrint("ARKitReferenceImage: loaded image has no CGImage for name: \(name)")
24+
return nil
25+
}
26+
27+
let referenceImage = ARReferenceImage(cgImage, orientation: CGImagePropertyOrientation.up, physicalWidth: CGFloat(physicalWidth))
28+
referenceImage.name = name
29+
return referenceImage
2030
}

0 commit comments

Comments
 (0)