This repository was archived by the owner on Aug 8, 2023. It is now read-only.
Repository navigation
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
MapSnapshotter callback is not always invoked #11669
Copy link
Copy link
Closed
Description
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
stale commentedon Oct 24, 2018
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.
stale commentedon Dec 7, 2018
This issue has been automatically detected as stale because it has not had recent activity and will be archived. Thank you for your contributions.
LukasPaczos commentedon Jul 18, 2019
After re-introduction of a
MapSnapshottertest 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
[android] ignore a flaky MapSnapshotter test until #11669 is resolved
[android] ignore a flaky MapSnapshotter test until #11669 is resolved
[android] ignore a flaky MapSnapshotter test until #11669 is resolved
[android] ignore a flaky MapSnapshotter test until #11669 is resolved
chloekraw commentedon Mar 6, 2020
cc @alexshalamov
brandikun commentedon Mar 24, 2020
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.
tobrun commentedon Mar 24, 2020
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).