Search code examples
iosmapboxmetalmapbox-ios

App crashing when loading RasterLayer - Mipmaps level count must be greater than 1


My team is in the process of updating to Mapbox v10. We have several tile map layers that are all crashing immediately upon loading.

One weird thing I've noticed is that the crash only happens when connected to Xcode debugger. If I launch the app directly from the device, everything works as expected.

It looks like the crash is Metal-related, but Mapbox is supposed to abstract away all of the Metal code, so I'm not sure if this is a me bug or a Mapbox bug.

The error:

[MTLDebugBlitCommandEncoder generateMipmapsForTexture:]:1109: failed assertion `Generate Mipmaps For Texture Validation [tex mipmapLevelCount](1) must be > 1.'

The code:

private func prepareFrames() {
  // Array of String
  for frame in tileFrameProvider.frames {
    let currentTimeString = "\(Date().timeIntervalSince1970))"
    let layerID = frame + mapOverlay.name + currentTimeString
    let sourceID = frame + mapOverlay.name + "source" + currentTimeString
    let url = urlTemplate.replacingOccurrences(of: "{t}", with: frame)
    
    var source = RasterSource()
    source.tiles = [url]
    source.tileSize = Double(tileSize)
    sources.append(source)
    
    var rasterLayer = RasterLayer(id: layerID)
    rasterLayer.source = sourceID
    rasterLayer.rasterOpacity = .constant(Double(initialAlpha))
    rasterLayers.append(rasterLayer)
  }

  guard tileFrameProvider.frames.count != 0 else { return }
    
  for (index, source) in self.sources.enumerated() {
        if let layer = self.rasterLayers[safeIndex: index] {
            try? self.mapView.mapboxMap.style.addSource(source, id: layer.source ?? "")
            try? self.mapView.mapboxMap.style.addLayer(layer, layerPosition: .above("building-line"))
        }
    }
}

Solution

  • Looks like it is a Mapbox bug. My app doesn't use Metal and disabling Metal API Validation stops the crash from happening. enter image description here