Drawing MKPolylines on map make app unresponsive. Anybody else have this problem ?

In our app we draw lines on roads in apple maps. So we draw multiple polylines (MKPolyline) on a map view. In iOS 16 this functionality is making the application non-responsive.

This was working up until iOS 16

Steps to Reproduce:

Create a Custom Map renderer for iOS Add multiple polylines (MKPolyline.FromCoordinates) with MKMapView.AddOverlay When zooming in/out on the map it removes the existing shapes and redraws them. Doing this once or multiple times makes the app non-responsive. After some time the app crashes.

Anybody else experiencing this ?

Seems that we always get this before the crash:

[VKDefault] Exceeded Metal Buffer threshold of 50000 with a count of 51635 resources, pruning resources now (Time since last prune:31.189292): Assertion with expression - false : Failed in file - /Library/Caches/com.apple.xbs/Sources/VectorKit/src/MDMapEngine.mm line - 1363

To be even more precise, this issue started with iOS 16.1.

Same problem on iOS 16 with MapKit and overlays. After some moving/zooming in-out app hags and crashes with console log

`[VKDefault] Exceeded Metal Buffer threshold of 50000 with a count of 51809 resources, pruning resources now (Time since last prune:113742.196925): Assertion with expression - false : Failed in file - /Library/Caches/com.apple.xbs/Sources/VectorKit/src/MDMapEngine.mm line - 1363

Same issue, but seems to only affect iOS 16.1. Happens after zooming and panning around a map with many MKPolylines and MKPolygons

[VKDefault] Exceeded Metal Buffer threshold of 50000 with a count of 59670 resources, pruning resources now (Time since last prune:21.620829): Assertion with expression - false : Failed in file - /Library/Caches/com.apple.xbs/Sources/VectorKit/src/MDMapEngine.mm line - 1363

Filed an issue for this: FB11774719

Important: After some more investigating, to be more precise, this issues seems to be popping up as of 16.1.

This issues seems to have started with 16.1.

 many MKPolylines and MKPolygons

By "many", do you mean thousands or millions? Are they all visible, or are many of them off-screen? How does the number of lines or points compare with the 50000 number in the error message?

I'm posting this workaround that we found and implemented in our project. The work around for us until apple fixes the issue is after the call to .addOverlay of the polylines we do (our map is on .standard normally):

mapView.mapType = MKMapType.hybrid mapView.mapType = MKMapType.standard

The switch is not perceivable, but makes the map flicker a little, but more importantly it seems it clears the app cache and stops the whole map and app from freezing.

See source: https://stackoverflow.com/questions/69248520/vkdefault-triangulator-failed-to-fully-triangulate-polygon-mapkit

For the beefier numbers of polylines we had to reduce the number being added as even with the workaround some big numbers were still creating freezes.

We are having the same issue. We use iOS 16.1 (not sure if it happens with iOS 16.0).

We have a micromobility (scooter rental) app and we have mkpolygons there. After zooming in and zooming out couple of times, console prints this error of exceeding metal buffer threshold and then app gets completely unresponsive. It is not crashing, but it gets frozen and user has no option other than to kill the app. We found out that setting mapType to something else (i.e. satellite) and then back to standard solves the issue as it clears mapView's cache. However, that creates massive flickering issue and we don't want to create another issue for solution to another.

Did you come up with anything or are you still waiting solution?

Same problem here, our mission planning app (with MKpolylines on the map) now get non-responsive with iOS16.1 while editing the mission. Anyone found a solution that is not changing mapstyle?

It seems as the problem might be related to the number of MKOverlayRenderers making draw calls. Using MKMultiPolyline/Polygon seems to be a workaround but that does not work if you need to support iOS 12 or style the lines and polygons differently.

I'm getting this very quickly in areas that require a lot of MKPolylineRenderer / MKPolygonRenderer / MKMultiPolygonRenderer. I have tried changing mapType on when moving about, before removing/adding new overlays, but it's just totally flaking out on iOS 16.1.1. This is kind of a critical issue for us as it's breaking our production application. Has anyone got any insight into this this recently?

iOS 16.1.2 didn't fix this issue, I was wondering about the betas if anyone has tried. Would be interesting to know apple guidance about this, should we just wait for a fix at o/s level and avoid any complex rendering in the meantime ? I had to disable some of the features when my app is running on iOS16, users were complaining about freezes.

Would be interesting to know apple guidance about this

Apple don't comment on their future plans, including their future plans regarding fixing bugs.

I had to disable some of the features when my app is running on iOS16

That's a good approach, but beware, you need to be careful about what you put in the "what's new" information in App Store Connect.

The alternative is to replace MKMapKit with something else, where there is more responsive upstream support, where you can fix bugs yourself if necessary, and where you are in control of when it is upgraded to new versions.

Drawing MKPolylines on map make app unresponsive. Anybody else have this problem ?
 
 
Q