Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't call initialize twice when getStyle callback fires several times. #1112

Merged
merged 3 commits into from
Feb 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Mapbox welcomes participation and contributions from everyone.

## Bug fixes 🐞
* Fix skipping / crashing user events scheduled on a render thread with `MapView#queueEvent`. ([#1068](https://github.com/mapbox/mapbox-maps-android/pull/1068))
* Fix crash within location plugin that happens when style is reloaded simultaneously with location plugin updates. ([#1112](https://github.com/mapbox/mapbox-maps-android/pull/1112))

# 10.3.0 February 7, 2022

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,7 @@ class LocationComponentPluginImpl : LocationComponentPlugin, LocationConsumer,
)
)
}
locationPuckManager?.let {
if (!it.isLayerInitialised()) {
it.initialize(style)
}
}
locationPuckManager?.initialize(style)
yunikkk marked this conversation as resolved.
Show resolved Hide resolved
locationPuckManager?.onStart()
locationProvider?.registerLocationConsumer(this)
isLocationComponentActivated = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,22 @@ internal class LocationPuckManager(
}

fun initialize(style: StyleInterface) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initialize method called from updateSettings waits for the style at getStyle.
If updateSettings was called multiple times multiple callbacks will fire after style arrives causing crash.

animationManager.setUpdateListeners(onLocationUpdated, onBearingUpdated)
animationManager.setLocationLayerRenderer(locationLayerRenderer)
animationManager.applyPulsingAnimationSettings(settings)
locationLayerRenderer.addLayers(positionManager)
lastLocation?.let {
updateCurrentPosition(it)
}
updateCurrentBearing(lastBearing)
locationLayerRenderer.initializeComponents(style)
styleScaling(settings)
if (lastLocation != null && settings.enabled) {
show()
} else {
hide()
if (!locationLayerRenderer.isRendererInitialised()) {
kiryldz marked this conversation as resolved.
Show resolved Hide resolved
animationManager.setUpdateListeners(onLocationUpdated, onBearingUpdated)
animationManager.setLocationLayerRenderer(locationLayerRenderer)
animationManager.applyPulsingAnimationSettings(settings)
locationLayerRenderer.addLayers(positionManager)
lastLocation?.let {
updateCurrentPosition(it)
}
updateCurrentBearing(lastBearing)
locationLayerRenderer.initializeComponents(style)
styleScaling(settings)
if (lastLocation != null && settings.enabled) {
show()
} else {
hide()
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,22 +197,6 @@ class LocationComponentPluginImplTest {
assertEquals(mockLocationProvider, locationComponentPlugin.getLocationProvider())
}

@Test
fun testOnStyleChanged() {
every { locationPuckManager.isLayerInitialised() } returns false
preparePluginInitialisationWithEnabled()
verify(exactly = 2) { locationPuckManager.isLayerInitialised() }
verify(exactly = 1) { locationPuckManager.initialize(style) }
}

@Test
fun testOnStyleChangedWhilePuckManagerInitialised() {
every { locationPuckManager.isLayerInitialised() } returns true
preparePluginInitialisationWithEnabled()
verify(exactly = 2) { locationPuckManager.isLayerInitialised() }
verify(exactly = 0) { locationPuckManager.initialize(style) }
}

kiryldz marked this conversation as resolved.
Show resolved Hide resolved
@Test
fun testOnStart() {
every { locationPuckManager.isLayerInitialised() } returns false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,20 @@ class LocationPuckManagerTest {
)
}

@Test
fun testDoesntInitialiseIfRendererInitialised() {
every { locationLayerRenderer.isRendererInitialised() } returns true

locationPuckManager.initialize(style)

verify(exactly = 0) { animationManager.setLocationLayerRenderer(locationLayerRenderer) }
verify(exactly = 0) { animationManager.setUpdateListeners(any(), any()) }
verify(exactly = 0) { animationManager.applyPulsingAnimationSettings(settings) }
verify(exactly = 0) { locationLayerRenderer.addLayers(positionManager) }
verify(exactly = 0) { locationLayerRenderer.initializeComponents(style) }
verify(exactly = 0) { locationLayerRenderer.hide() }
}

private companion object {
const val MODEL_SCALE_CONSTANT = 2965820.800757861
}
Expand Down