Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

MapSnapshotter callback is not always invoked #11669

Closed

Description

@fdermishin-radargeo

Platform: Android
Mapbox SDK version: 5.5.2, 6.0.0-beta.6

Steps to trigger behavior

There is a simple layout containing button and imageView. Clicking on button starts MapSnapshotter.

import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import com.mapbox.mapboxsdk.Mapbox
import com.mapbox.mapboxsdk.camera.CameraPosition
import com.mapbox.mapboxsdk.geometry.LatLng
import com.mapbox.mapboxsdk.snapshotter.MapSnapshotter
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        Mapbox.getInstance(this, "XXXXXX")
    }

    fun onButtonClick(button: View) {
        val location = LatLng(52 + Math.random(), 13 + Math.random())
        val width = imageView.width
        val height = imageView.height

        val cameraPosition = CameraPosition.Builder()
                .target(location)
                .zoom(12.0)
                .build()
        val options = MapSnapshotter.Options(width, height)
                .withCameraPosition(cameraPosition)

        imageView.setImageDrawable(null)
        MapSnapshotter(this, options).start({ snapshot ->
            imageView.setImageBitmap(snapshot.bitmap)
        }, {
            imageView.setImageDrawable(ColorDrawable(Color.RED))
        })
    }
}
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:onClick="onButtonClick"
        android:text="Button"
        app:layout_constraintBottom_toTopOf="@id/imageView"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="0dp"
        android:layout_height="200dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/button"
        app:srcCompat="@android:color/darker_gray" />
</android.support.constraint.ConstraintLayout>

Expected behavior

After each press imageView displays either a map snapshot or it becomes red.

Actual behavior

Sometimes neither SnapshotReadyCallback nor ErrorHandler is called, so imageView remains blank.

Activity

  1. added
    Android
    on Apr 12, 2018
  2. stale commented on Oct 24, 2018

    @stale

    This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

  3. added
    archived
    on Oct 24, 2018
  4. stale commented on Dec 7, 2018

    @stale

    This issue has been automatically detected as stale because it has not had recent activity and will be archived. Thank you for your contributions.

  5. LukasPaczos commented on Jul 18, 2019

    @LukasPaczos
    Contributor

    After re-introduction of a MapSnapshotter test in #15121 and error logging in #15141, we're seeing tests timing out (30 seconds without a snapshot being delivered), even though there's no error emitted from core.

    Example builds:

    /cc @tobrun @tmpsantos

  6. removed
    archived
    on Jul 18, 2019
  7. chloekraw commented on Mar 6, 2020

    @chloekraw
    Contributor
  8. added
    Core
    on Mar 6, 2020
  9. brandikun commented on Mar 24, 2020

    @brandikun

    I am also using snapshotter in kotlin for Android and it typically takes about 3 tries before I can get the callback to fire. No crash, no error emitted.

  10. tobrun commented on Mar 24, 2020

    @tobrun
    Member

    We were able to boil this down to the Snapshotter object being garbage collected before returning the result, solution is to retain the snapshotter instance (eg. scope it to the hosting class).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    AndroidCore

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions