Prevent crashes on non-existing assets

This commit is contained in:
Kelvin 2024-12-19 22:00:56 +01:00
parent f73e25ece6
commit aaa2d7f08d

View file

@ -1,6 +1,7 @@
package com.futo.platformplayer.states
import android.content.Context
import com.futo.platformplayer.logging.Logger
import kotlin.streams.asSequence
/***
@ -45,10 +46,16 @@ class StateAssets {
var text: String?;
synchronized(_cache) {
if (!_cache.containsKey(path)) {
text = context.assets
?.open(path)
?.bufferedReader()
?.use { it.readText(); };
try {
text = context.assets
?.open(path)
?.bufferedReader()
?.use { it.readText(); };
}
catch(ex: Throwable) {
Logger.e("StateAssets", "Could not open asset: " + path, ex);
return null;
}
_cache.put(path, text);
} else {