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

Android: Random crash in LocationComponent #14889

Closed
mdakram opened this issue Jun 11, 2019 · 12 comments · Fixed by mapbox/mapbox-gl-native-android#19
Closed

Android: Random crash in LocationComponent #14889

mdakram opened this issue Jun 11, 2019 · 12 comments · Fixed by mapbox/mapbox-gl-native-android#19
Assignees
Labels
Android Mapbox Maps SDK for Android crash

Comments

@mdakram
Copy link

mdakram commented Jun 11, 2019

Steps to reproduce

Its not happening on bench level testing. getting crashes on play store.

Fatal Exception: java.lang.IllegalStateException: Calling getSourceAs when a newer style is loading/has loaded.
       at com.mapbox.mapboxsdk.maps.Style.validateState(Style.java:522)
       at com.mapbox.mapboxsdk.maps.Style.getSourceAs(Style.java:132)
       at com.mapbox.mapboxsdk.location.LocationLayerController.refreshSource(LocationLayerController.java:291)
       at com.mapbox.mapboxsdk.location.LocationLayerController.setBearingProperty(LocationLayerController.java:273)
       at com.mapbox.mapboxsdk.location.LocationLayerController.access$100(LocationLayerController.java:61)
       at com.mapbox.mapboxsdk.location.LocationLayerController$3.onNewAnimationValue(LocationLayerController.java:437)
       at com.mapbox.mapboxsdk.location.LocationLayerController$3.onNewAnimationValue(LocationLayerController.java:434)
       at com.mapbox.mapboxsdk.location.MapboxAnimator.postUpdates(MapboxAnimator.java:83)
       at com.mapbox.mapboxsdk.location.MapboxAnimator.onAnimationUpdate(MapboxAnimator.java:71)
       at android.animation.ValueAnimator.animateValue(ValueAnimator.java:1463)
       at android.animation.ValueAnimator.setCurrentFraction(ValueAnimator.java:642)
       at android.animation.ValueAnimator.setCurrentPlayTime(ValueAnimator.java:589)
       at android.animation.ValueAnimator.start(ValueAnimator.java:1106)
       at android.animation.ValueAnimator.start(ValueAnimator.java:1117)
       at android.animation.AnimatorSet.start(AnimatorSet.java:586)
       at com.mapbox.mapboxsdk.location.MapboxAnimatorSetProvider.startAnimation(MapboxAnimatorSetProvider.java:30)
       at com.mapbox.mapboxsdk.location.LocationAnimatorCoordinator.playAnimators(LocationAnimatorCoordinator.java:291)
       at com.mapbox.mapboxsdk.location.LocationAnimatorCoordinator.feedNewCompassBearing(LocationAnimatorCoordinator.java:116)
       at com.mapbox.mapboxsdk.location.LocationComponent.updateCompassHeading(LocationComponent.java:1293)
       at com.mapbox.mapboxsdk.location.LocationComponent.access$900(LocationComponent.java:93)
       at com.mapbox.mapboxsdk.location.LocationComponent$7.onCompassChanged(LocationComponent.java:1415)
       at com.mapbox.mapboxsdk.location.LocationComponentCompassEngine.notifyCompassChangeListeners(LocationComponentCompassEngine.java:201)
       at com.mapbox.mapboxsdk.location.LocationComponentCompassEngine.updateOrientation(LocationComponentCompassEngine.java:196)
       at com.mapbox.mapboxsdk.location.LocationComponentCompassEngine.onSensorChanged(LocationComponentCompassEngine.java:124)
       at android.hardware.SystemSensorManager$SensorEventQueue.dispatchSensorEvent(SystemSensorManager.java:988)
       at android.os.MessageQueue.nativePollOnce(MessageQueue.java)
       at android.os.MessageQueue.next(MessageQueue.java:328)
       at android.os.Looper.loop(Looper.java:164)
       at android.app.ActivityThread.main(ActivityThread.java:5790)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1015)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:876)

Expected behavior

It should not crash

Actual behavior

Application is crashing

Configuration

Android versions: 5,6,7 and 8
Device models: Samsung, VIVO, Xiomi, OPPO
Mapbox SDK versions: 7.3.2

@tobrun tobrun added the Android Mapbox Maps SDK for Android label Jun 11, 2019
@tobrun
Copy link
Member

tobrun commented Jun 11, 2019

@mdakram are you allowing users to load a new style in your application?

@mdakram
Copy link
Author

mdakram commented Jun 11, 2019

Hi @tobrun yes.

@dsuresh-ap
Copy link

I think I have the same issue, has this issue been resolved in any of the current versions. It has been happening on 8.1.0

@dsuresh-ap
Copy link

I see that the reference issue has it fixed in 8.0.2's release however that release is newer than 8.2.1. Does 8.2.1 have all the updated changes?

@LukasPaczos
Copy link
Member

@dsuresh-ap do you have a reproducible example by any chance?

@dsuresh-ap
Copy link

@LukasPaczos I do not at the moment as it was reported by our QA on a Samsung S4 32-Bit running Android 4.4.4. It happebedThe same crash doesn't happen on any newer OSes.

Below is the StackTrace.

java.lang.IllegalStateException: Calling getSourceAs when a newer style is loading/has loaded.
	at com.mapbox.mapboxsdk.maps.Style.isFullyLoaded(Unknown Source:19)
                                    validateState
	at com.mapbox.mapboxsdk.maps.Style.getSourceAs(Unknown Source:2)
                                    getSources
	at com.mapbox.mapboxsdk.location.LocationLayerController.refreshSource(Unknown Source:4)
	at com.mapbox.mapboxsdk.location.LocationLayerController.access$000(Unknown Source:9)
                                                          access$100
                                                          access$200
                                                          addLayerToMap
                                                          addSymbolLayer
                                                          applyStyle
                                                          getAnimationListeners
                                                          initializeComponents
                                                          onMapClick
                                                          setBearingProperty
                                                          setLayerVisibility
                                                          setLocationPoint
                                                          setLocationsStale
                                                          setRenderMode
                                                          styleAccuracy
                                                          updateForegroundBearing
                                                          updateForegroundOffset
	at com.mapbox.mapboxsdk.location.LocationLayerController.access$000(Unknown Source:0)
                                                          access$100
                                                          access$200
                                                          addLayerToMap
                                                          addSymbolLayer
                                                          applyStyle
                                                          getAnimationListeners
                                                          initializeComponents
                                                          onMapClick
                                                          setBearingProperty
                                                          setLayerVisibility
                                                          setLocationPoint
                                                          setLocationsStale
                                                          setRenderMode
                                                          styleAccuracy
                                                          updateForegroundBearing
                                                          updateForegroundOffset
	at com.mapbox.mapboxsdk.location.LocationLayerController$3.onNewAnimationValue(Unknown Source:8)
                                                            onNewAnimationValue
	at com.mapbox.mapboxsdk.location.LocationLayerController$3.onNewAnimationValue(Unknown Source:2)
                                                            onNewAnimationValue
	at com.mapbox.mapboxsdk.location.MapboxAnimator.postUpdates(Unknown Source:4)
	at com.mapbox.mapboxsdk.location.MapboxAnimator.onAnimationUpdate(Unknown Source:22)
	at android.animation.ValueAnimator.animateValue(ValueAnimator.java:1547)
	at android.animation.ValueAnimator.setCurrentFraction(ValueAnimator.java:674)
	at android.animation.ValueAnimator.setCurrentPlayTime(ValueAnimator.java:637)
	at android.animation.ValueAnimator.start(ValueAnimator.java:1069)
	at android.animation.ValueAnimator.start(ValueAnimator.java:1088)
	at android.animation.ValueAnimator.startWithoutPulsing(ValueAnimator.java:1081)
	at android.animation.AnimatorSet.handleAnimationEvents(AnimatorSet.java:1142)
	at android.animation.AnimatorSet.startAnimation(AnimatorSet.java:1227)
	at android.animation.AnimatorSet.start(AnimatorSet.java:729)
	at android.animation.AnimatorSet.start(AnimatorSet.java:684)
	at com.mapbox.mapboxsdk.location.MapboxAnimatorSetProvider.getInstance(Unknown Source:14)
                                                            startAnimation
	at com.mapbox.mapboxsdk.location.LocationAnimatorCoordinator.cancelAllAnimations(Unknown Source:34)
                                                              checkGpsNorth
                                                              createNewCameraAdapterAnimator
                                                              createNewFloatAnimator
                                                              createNewLatLngAnimator
                                                              feedNewAccuracyRadius
                                                              feedNewCompassBearing
                                                              feedNewLocation
                                                              feedNewTilt
                                                              playAnimators
                                                              resetAllCameraAnimations
                                                              resetCameraCompassAnimation
                                                              setAccuracyAnimationEnabled
                                                              setMaxAnimationFps
                                                              setTrackingAnimationDurationMultiplier
                                                              updateAccuracyAnimators
                                                              updateAnimatorListenerHolders
                                                              updateCameraAnimators
                                                              updateCompassAnimators
                                                              updateLayerAnimators
                                                              updateTiltAnimator
	at com.mapbox.mapboxsdk.location.LocationAnimatorCoordinator.cancelAllAnimations(Unknown Source:34)
                                                              checkGpsNorth
                                                              createNewCameraAdapterAnimator
                                                              createNewFloatAnimator
                                                              createNewLatLngAnimator
                                                              feedNewAccuracyRadius
                                                              feedNewCompassBearing
                                                              feedNewLocation
                                                              feedNewTilt
                                                              playAnimators
                                                              resetAllCameraAnimations
                                                              resetCameraCompassAnimation
                                                              setAccuracyAnimationEnabled
                                                              setMaxAnimationFps
                                                              setTrackingAnimationDurationMultiplier
                                                              updateAccuracyAnimators
                                                              updateAnimatorListenerHolders
                                                              updateCameraAnimators
                                                              updateCompassAnimators
                                                              updateLayerAnimators
                                                              updateTiltAnimator
	at com.mapbox.mapboxsdk.location.LocationComponent.access$100(Unknown Source:8)
                                                    access$1000
                                                    access$300
                                                    access$900
                                                    activateLocationComponent
                                                    activateLocationComponent
                                                    activateLocationComponent
                                                    activateLocationComponent
                                                    activateLocationComponent
                                                    activateLocationComponent
                                                    activateLocationComponent
                                                    activateLocationComponent
                                                    activateLocationComponent
                                                    activateLocationComponent
                                                    activateLocationComponent
                                                    activateLocationComponent
                                                    activateLocationComponent
                                                    addOnCameraTrackingChangedListener
                                                    addOnLocationClickListener
                                                    addOnLocationLongClickListener
                                                    addOnLocationStaleListener
                                                    addOnRenderModeChangedListener
                                                    applyStyle
                                                    applyStyle
                                                    cancelTiltWhileTrackingAnimation
                                                    forceLocationUpdate
                                                    initializeLocationEngine
                                                    setCameraMode
                                                    setCameraMode
                                                    setCameraMode
                                                    setCompassEngine
                                                    setLocationComponentEnabled
                                                    setLocationEngine
                                                    setLocationEngineRequest
                                                    tiltWhileTracking
                                                    tiltWhileTracking
                                                    tiltWhileTracking
                                                    updateAccuracyRadius
                                                    updateCompassHeading
	at com.mapbox.mapboxsdk.location.LocationComponent.access$100(Unknown Source:0)
                                                    access$1000
                                                    access$300
                                                    access$900
                                                    activateLocationComponent
                                                    activateLocationComponent
                                                    activateLocationComponent
                                                    activateLocationComponent
                                                    activateLocationComponent
                                                    activateLocationComponent
                                                    activateLocationComponent
                                                    activateLocationComponent
                                                    activateLocationComponent
                                                    activateLocationComponent
                                                    activateLocationComponent
                                                    activateLocationComponent
                                                    activateLocationComponent
                                                    addOnCameraTrackingChangedListener
                                                    addOnLocationClickListener
                                                    addOnLocationLongClickListener
                                                    addOnLocationStaleListener
                                                    addOnRenderModeChangedListener
                                                    applyStyle
                                                    applyStyle
                                                    cancelTiltWhileTrackingAnimation
                                                    forceLocationUpdate
                                                    initializeLocationEngine
                                                    setCameraMode
                                                    setCameraMode
                                                    setCameraMode
                                                    setCompassEngine
                                                    setLocationComponentEnabled
                                                    setLocationEngine
                                                    setLocationEngineRequest
                                                    tiltWhileTracking
                                                    tiltWhileTracking
                                                    tiltWhileTracking
                                                    updateAccuracyRadius
                                                    updateCompassHeading
	at com.mapbox.mapboxsdk.location.LocationComponent$7.onCompassAccuracyChange(Unknown Source:2)
                                                      onCompassChanged
	at com.mapbox.mapboxsdk.location.LocationComponentCompassEngine.getLastAccuracySensorStatus(Unknown Source:18)
                                                                 getRotationVectorFromSensorEvent
                                                                 lowPassFilter
                                                                 notifyCompassChangeListeners
                                                                 removeCompassListener
	at com.mapbox.mapboxsdk.location.LocationComponentCompassEngine.updateOrientation(Unknown Source:77)
	at com.mapbox.mapboxsdk.location.LocationComponentCompassEngine.onSensorChanged(Unknown Source:39)
	at android.hardware.SystemSensorManager$SensorEventQueue.dispatchSensorEvent(SystemSensorManager.java:981)
	at android.os.MessageQueue.nativePollOnce(Native Method)
	at android.os.MessageQueue.next(MessageQueue.java:326)
	at android.os.Looper.loop(Looper.java:181)
	at android.app.ActivityThread.main(ActivityThread.java:7050)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:964)

@LukasPaczos
Copy link
Member

Thanks for reports and traces @mdakram, @dsuresh-ap. I was able to reproduce the issue - run a clean install of an app -> load a map and location component -> disable internet -> change style (loading constantly in-progress because of lack of the internet) -> set camera/render mode to any that track compass updates.

@mdakram
Copy link
Author

mdakram commented Oct 1, 2019

@LukasPaczos good its reproduced at your end, i was not able to reproduce.
When we can expect this in SDK?

@jheikkola
Copy link

jheikkola commented Oct 3, 2019

I've seen this same issue with 8.4.0 but can't reproduce reliably. I've just disabled animations in location component options, hoping that will avoid the problem.

@pengdev
Copy link
Member

pengdev commented Oct 11, 2019

This issue seems to be caused by LocationLayerController is trying to update an old style when the new style is loaded(or the style is not loaded). This could be possibly resolved by refactor the LocationLayerController to not keeping a reference of the style but instead use mapboxMap.getStyle(callback) async call to get the latest style every time when needed.

@LukasPaczos
Copy link
Member

LukasPaczos commented Oct 11, 2019

@pengdev while that would be the ideal solution, changing impl to the async mapboxMap.getStyle might introduce a cascade of other issues. From quickly glancing the code, it looks like the compass engine is correctly disabled when the style is about to change (in onLocationLayerStop) but is then re-enabled when the camera is changed before the style is loaded. I believe that adding a !isLayerReady here might resolve the issue:

if (!isComponentInitialized || !isComponentStarted || !isEnabled) {

@haoyh
Copy link

haoyh commented Oct 17, 2019

I have the same issue that version is 8.3.1 .
my way is call locationComponent.setLocationComponentEnabled(false) before call mapView.onDestroy() to avoid it.

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