Skip to content

Commit

Permalink
never call the MapController after it has been destroyed (fixes #4259)
Browse files Browse the repository at this point in the history
  • Loading branch information
westnordost committed Aug 3, 2022
1 parent 73c38e6 commit 4b5a1f9
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ class EditHistoryPinsManager(
}

private fun stop() {
pinsMapComponent.clear()
viewLifecycleScope.coroutineContext.cancelChildren()
viewLifecycleScope.launch { pinsMapComponent.clear() }
editHistorySource.removeListener(editHistoryListener)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,7 @@ class QuestPinsManager(

private val visibleQuestsListener = object : VisibleQuestsSource.Listener {
override fun onUpdatedVisibleQuests(added: Collection<Quest>, removed: Collection<QuestKey>) {
synchronized(questsInView) {
added.forEach { questsInView[it.key] = createQuestPins(it) }
removed.forEach { questsInView.remove(it) }
}
updatePins()
viewLifecycleScope.launch { updateQuestPins(added, removed) }
}

override fun onVisibleQuestsInvalidated() {
Expand Down Expand Up @@ -92,8 +88,8 @@ class QuestPinsManager(
}

private fun stop() {
clear()
viewLifecycleScope.coroutineContext.cancelChildren()
clear()
visibleQuestsSource.removeListener(visibleQuestsListener)
questTypeOrderSource.removeListener(questTypeOrderListener)
}
Expand All @@ -106,7 +102,7 @@ class QuestPinsManager(
private fun clear() {
synchronized(questsInView) { questsInView.clear() }
lastDisplayedRect = null
pinsMapComponent.clear()
viewLifecycleScope.launch { pinsMapComponent.clear() }
}

fun getQuestKey(properties: Map<String, String>): QuestKey? =
Expand All @@ -130,16 +126,25 @@ class QuestPinsManager(
val bbox = tilesRect.asBoundingBox(TILES_ZOOM)
viewLifecycleScope.launch {
val quests = withContext(Dispatchers.IO) { visibleQuestsSource.getAllVisible(bbox) }
synchronized(questsInView) {
questsInView.clear()
quests.forEach { questsInView[it.key] = createQuestPins(it) }
}
updatePins()
setQuestPins(quests)
}
}

private fun updatePins() {
val pins = synchronized(questsInView) { questsInView.values.flatten() }
private fun setQuestPins(quests: List<Quest>) {
val pins = synchronized(questsInView) {
questsInView.clear()
quests.forEach { questsInView[it.key] = createQuestPins(it) }
questsInView.values.flatten()
}
pinsMapComponent.set(pins)
}

private fun updateQuestPins(added: Collection<Quest>, removed: Collection<QuestKey>) {
val pins = synchronized(questsInView) {
added.forEach { questsInView[it.key] = createQuestPins(it) }
removed.forEach { questsInView.remove(it) }
questsInView.values.flatten()
}
pinsMapComponent.set(pins)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class StyleableOverlayManager(

private val mapDataListener = object : MapDataWithEditsSource.Listener {
override fun onUpdated(updated: MapDataWithGeometry, deleted: Collection<ElementKey>) {
updateStyledElements(updated, deleted)
viewLifecycleScope.launch { updateStyledElements(updated, deleted) }
}

override fun onReplacedForBBox(bbox: BoundingBox, mapDataWithGeometry: MapDataWithGeometry) {
Expand Down Expand Up @@ -90,17 +90,11 @@ class StyleableOverlayManager(
}

private fun hide() {
clear()
viewLifecycleScope.coroutineContext.cancelChildren()
clear()
mapDataSource.removeListener(mapDataListener)
}

private fun clear() {
synchronized(mapDataInView) { mapDataInView.clear() }
lastDisplayedRect = null
mapComponent.clear()
}

fun onNewScreenPosition() {
if (overlay == null) return
val zoom = ctrl.cameraPosition.zoom
Expand All @@ -123,6 +117,12 @@ class StyleableOverlayManager(
}
}

private fun clear() {
synchronized(mapDataInView) { mapDataInView.clear() }
lastDisplayedRect = null
viewLifecycleScope.launch { mapComponent.clear() }
}

private fun setStyledElements(mapData: MapDataWithGeometry) {
val layer = overlay ?: return
synchronized(mapDataInView) {
Expand Down

0 comments on commit 4b5a1f9

Please sign in to comment.