Prevent a delayed coroutine from crashing

Checking state when the function is called only works if the coroutine is fired immediately. If it is delayed by another process, it will crash with a ClassCastException
This commit is contained in:
Abandoned Cart 2023-04-20 11:58:50 -04:00
parent d3d36c6fa0
commit 49f666cd8d

View File

@ -78,8 +78,8 @@ class MainViewModel @Inject constructor(@ApplicationContext context : Context, p
* This checks if the roms have changed since the last time they were loaded and if so it reloads them
*/
fun checkRomHash(searchLocation : Uri, systemLanguage : Int) {
if(state !is MainState.Loaded) return
CoroutineScope(Dispatchers.IO).launch {
if (state !is MainState.Loaded) return@launch
val currentHash = (state as MainState.Loaded).items.hashCode()
val romElements = romProvider.loadRoms(searchLocation, systemLanguage)
val newHash = romElements.hashCode()