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

MapSnapshotter callback is not always invoked #11669

Closed
fdermishin-radargeo opened this issue Apr 12, 2018 · 6 comments
Closed

MapSnapshotter callback is not always invoked #11669

fdermishin-radargeo opened this issue Apr 12, 2018 · 6 comments
Labels
Android Mapbox Maps SDK for Android Core The cross-platform C++ core, aka mbgl

Comments

@fdermishin-radargeo
Copy link

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.

@fabian-guerra fabian-guerra added the Android Mapbox Maps SDK for Android label Apr 12, 2018
@stale
Copy link

stale bot commented 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 stale bot added the archived Archived because of inactivity label Oct 24, 2018
@stale
Copy link

stale bot commented 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.

@stale stale bot closed this as completed Dec 7, 2018
@LukasPaczos
Copy link
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

@chloekraw
Copy link
Contributor

cc @alexshalamov

@chloekraw chloekraw added the Core The cross-platform C++ core, aka mbgl label Mar 6, 2020
@brandikun
Copy link

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
Copy link
Member

tobrun commented 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).

@tobrun tobrun closed this as completed Mar 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Android Mapbox Maps SDK for Android Core The cross-platform C++ core, aka mbgl
Projects
None yet
Development

No branches or pull requests

7 participants