mapbox-maps-flutter icon indicating copy to clipboard operation
mapbox-maps-flutter copied to clipboard

Bug(android): Failed to create snapshot: snapshotting timed out.

Open thuan-savvycom opened this issue 1 year ago • 3 comments

MapBox version: 2.4.1 Sometimes I got a timed out exception:

Non-fatal Exception: io.flutter.plugins.firebase.crashlytics.FlutterError: PlatformException(2342345, Failed to create snapshot: snapshotting timed out., null, null)

I see in the android code, current timeout is 1 second. Can we increate the timeout?

@RenderThread
fun snapshot(): Bitmap? {
  if (!readyForSnapshot.get()) {
    logE(TAG, "Could not take map snapshot because map is not ready yet.")
    return null
  }
  val lock = ReentrantLock()
  val waitCondition = lock.newCondition()
  val legacyMode = snapshotLegacyModeEnabled
  lock.withLock {
    var snapshot: Bitmap? = null
    renderThread.queueRenderEvent(
      RenderEvent(
        runnable = {
          lock.withLock {
            snapshot = performSnapshot(legacyMode)
            waitCondition.signal()
          }
        },
        needRender = true,
      )
    )
    waitCondition.await(1, TimeUnit.SECONDS)
    return snapshot
  }
}

thuan-savvycom avatar Dec 02 '24 04:12 thuan-savvycom

Hi @thuan-savvycom, the timeout is defined statically on the Android side, not sure why it times out as snapshot should be ready in much less than 1 second, this could happen if the rendering queue is clogged, which is probably something that older devices more susceptible of. Could you give Snapshotter a go? It doesn't have any timeouts and it uses GPU rendering, so snapshots are usually delivered very quickly.

evil159 avatar Dec 02 '24 08:12 evil159

This issue occurs on flagship phones such as the Galaxy Z Fold6, Galaxy S21 5G, Moto G53 5G, and OnePlus 9 Pro 5G... I am using MapBox in my running application to draw the running route on the map. I use PolylineAnnotationManager to draw the route with thousands of coordinates. I tried using Snapshotter, but I couldn't capture the map including the polyline route.

thuan-savvycom avatar Dec 04 '24 04:12 thuan-savvycom

@thuan-savvycom As for the Snapshotter - you can style it in pretty much the same way as the map through the StyleManager(Snapshotter.style), including adding a poly line, one thing that is different that annotations are not supported, but using a combination of LineLayer and GeoJsonSource should enable you to achieve the same result(under the hood annotations are implemented this way).

evil159 avatar Jan 27 '25 12:01 evil159