Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Reached the max number of texture atlases, can not allocate more" using Google Maps

I'm building an app which uses Google Maps, and a lot of overlays, is seems like when I try to load a lot overlays it stall and provide me with "((null)) was false: Reached the max number of texture atlases, can not allocate more."

I'm just adding images as overlays this way:

...
if (image != nil) {
                let image: CGImage = (image?.cgImage)!
                let icon = UIImage(cgImage: image)

                let overlay = GMSGroundOverlay(bounds: overlayBounds, icon: icon)
                overlay.bearing = 0
                overlay.map = map
                overlay.zIndex = 10

                self.overlays.append(overlay);

Any suggestions on how to fix this issue?

like image 856
Recusiwe Avatar asked Apr 15 '17 18:04

Recusiwe


3 Answers

The problem appears to be that you are allocating a separate UIImage instance to each marker/overlay. This means that when you are plotting markers on the GMSMapView instance, each marker has a separate UIImage.

If you are creating several markers with the same image, use the same instance of UIImage for each of the markers. This helps improve the performance of your application when displaying many markers.

Simply put, you need to limit the overlays you append. Are your images dynamic or static? If it is the same image a simple solution is to define the image once and just add a reference to the same image when you append the overlay.

like image 52
lax1089 Avatar answered Nov 15 '22 22:11

lax1089


Instead of setting marker's iconView, set marker's icon. That too initializes the image outside of the for loop:

func displayMarkers() {
    let iconImage = UIImage(named: "locationgreen")
    for partner in partners {
        let lat : Double = Double(partner.location?.coordinates![1] ?? 0)
        let lng : Double = Double(partner.location?.coordinates![0] ?? 0)

        let position = CLLocationCoordinate2D(latitude: lat, longitude: lng)
        let marker = GMSMarker(position: position)
        marker.title = partner.name
        marker.icon = iconImage
    }
}
like image 43
Bhas Avatar answered Nov 16 '22 00:11

Bhas


Try

if let image = image {
    let overlay = GMSGroundOverlay(bounds: overlayBounds, icon: icon)
    overlay.bearing = 0
    overlay.map = map
    overlay.zIndex = 10

    self.overlays.append(overlay)
}
like image 43
Alistra Avatar answered Nov 15 '22 23:11

Alistra