From 8b76a7a4f4ab604c4d06bf7a53f0bc9e365d258b Mon Sep 17 00:00:00 2001 From: zhaoguomanong Date: Fri, 12 Aug 2022 11:04:23 +0800 Subject: [PATCH] avoid modifying serversCache serverList from multithreading Bug: app force close during updating subscribe Reroduce steps: quickly scroll up and down the RecyclerView during updating subscribe if the server list length is more than the screen height, the bug can be 100% reproduced Solution: reloadServerList from UI Thread Signed-off-by: zhaoguomanong --- .../main/kotlin/com/v2ray/ang/viewmodel/MainViewModel.kt | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/viewmodel/MainViewModel.kt b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/viewmodel/MainViewModel.kt index 7b56bdf4..6eb26e14 100644 --- a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/viewmodel/MainViewModel.kt +++ b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/viewmodel/MainViewModel.kt @@ -54,12 +54,8 @@ class MainViewModel(application: Application) : AndroidViewModel(application) { fun reloadServerList() { serverList = MmkvManager.decodeServerList() - viewModelScope.launch(Dispatchers.Default) { - updateCache() - launch(Dispatchers.Main) { - updateListAction.value = -1 - } - } + updateCache() + updateListAction.value = -1 } fun removeServer(guid: String) {