I’m getting an EXC_BAD_ACCESS (code=1, address=0x8)
error when trying to add a polyline to my Google Map.
If I comment out the line polyline.map = mapView
, everything works just fine.
Given the vagueness of the error, I’m unsure as to the root cause, or whether it’s just because the Simulator I’m running the app on is so slow. I’ve not been able to test it on a real device yet.
let path = GMSMutablePath()
for coordinate in route.polyline.geoJsonLinestring.coordinates {
path.add(CLLocationCoordinate2D(latitude: coordinate[1], longitude: coordinate[0]))
print(coordinate)
}
let bounds = GMSCoordinateBounds(path: path)
let cameraUpdate = GMSCameraUpdate.fit(bounds, withPadding: 16)
DispatchQueue.main.async { [self] in
let polyline = GMSPolyline(path: path)
polyline.strokeColor = UIColor(named: "AccentColor")!
polyline.strokeWidth = 5
polyline.map = mapView
mapView?.moveCamera(cameraUpdate)
}
The crash doesn’t necessarily happen straight away – when I zoom the map out after adding the polyline, that’s when it seems to crash most often.
Update:
I tried changing the GPU Frame Capture
setting in Edit Scheme
but it had no impact.
I also created a simple view with a map and a hardcoded 2 coordinate polyline, and it still crashes. This is literally it:
override func viewDidLoad() {
super.viewDidLoad()
var coordinates = [
[-2.9287110999999997, 54.8929171],
[-2.8932368, 54.8968314],
]
let path = GMSMutablePath()
for coordinate in coordinates {
path.add(CLLocationCoordinate2D(latitude: coordinate[1], longitude: coordinate[0]))
}
let bounds = GMSCoordinateBounds(path: path)
let cameraUpdate = GMSCameraUpdate.fit(bounds, withPadding: 16)
let polyline = GMSPolyline(path: path)
polyline.strokeColor = UIColor(named: "AccentColor")!
polyline.strokeWidth = 10
polyline.map = mapView
mapView?.moveCamera(cameraUpdate)
}
Crashes after the map fully loads, which takes about a minute.
The performance of Google Maps in the simulator in general is terrible. The map view always seems to take >1 minute to fully load (grey view with Google logo then the tiles eventually appear).
2
Answers
This appears to be a bug, as I can reproduce it with the
maps-sdk-for-ios-samples
demo app. I've filed a bug report here: https://issuetracker.google.com/issues/323404687You are simply setting your polyline at a wrong place. If you set a line at
viewDidLoad
, your map won’t be there, and the app will crash. You should set it atviewDidAppear
.The following is a screenshot from my iPhone sim.