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

Crash on rotation when camera tracking is active #14020

Closed
kptlronyttcna opened this issue Mar 2, 2019 · 2 comments · Fixed by #14292
Closed

Crash on rotation when camera tracking is active #14020

kptlronyttcna opened this issue Mar 2, 2019 · 2 comments · Fixed by #14292
Labels
Android Mapbox Maps SDK for Android

Comments

@kptlronyttcna
Copy link

Rotating device while camera tracking is active causes app to crash.

Steps to reproduce

  1. Add map
  2. Activate location and camera tracking
  3. Rotate device

Expected behavior

Rotate

Actual behavior

Crash

Configuration

Android versions: Tested on different versions
Device models: Tested on different devices
Mapbox SDK versions: 7.1.2

@LukasPaczos
Copy link
Member

Hey @kptlronyttcna, would you mind sharing a bit more about your setup, or ideally a minimal reproducible example? I'm unable to reproduce on v7.1.2 or master.

@LukasPaczos LukasPaczos added Android Mapbox Maps SDK for Android needs reproduction labels Mar 4, 2019
@kptlronyttcna
Copy link
Author

kptlronyttcna commented Mar 5, 2019

Here's a sample

val mapFragment: SupportMapFragment
if (savedInstanceState == null) {
    val fragmentTransaction = supportFragmentManager.beginTransaction()
    mapFragment = SupportMapFragment.newInstance()
    fragmentTransaction.add(R.id.map_container, mapFragment, "mapFragment")
    fragmentTransaction.commit()
} else {
    mapFragment = supportFragmentManager.findFragmentByTag("mapFragment") as SupportMapFragment
}

mapFragment.getMapAsync { mapboxMap ->
    mapboxMap.setStyle(Style.SATELLITE) { style ->
        mapboxMap.easeCamera(CameraUpdateFactory.zoomBy(14.0))
        mapboxMap.uiSettings.setAllGesturesEnabled(false)
        mapboxMap.locationComponent.apply {
            isLocationComponentEnabled = true
            activateLocationComponent(this@MainActivity, style)
            cameraMode = CameraMode.TRACKING_GPS
        }
        mapboxMap.addOnCameraIdleListener {
            if (mapboxMap.projection.visibleRegion.hashCode().toString().isEmpty()) {
                println("just to prevent optimization")
            }
        }
    }
}

Problem is after device rotation when the map is destroyed onCameraIdleListener still gets called. If you rotate the device (it might take multiple tries) you should see the following in the logcat:

E/Mbgl-NativeMapView: You're calling `latLngForPixel` after the `MapView` was destroyed, were you invoking it after `onDestroy()`?

Of course this sample wont cause a crash, but if I was for example modifying a layer in onCameraIdleListener the app would crash with a segment fault.

I was not able to reproduce this problem with a simple MapView (instead of fragment) or using CameraMode.TRACKING instead of CameraModel.TRACKING_GPS.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Android Mapbox Maps SDK for Android
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants