Skip to content

Commit aaa2d7f

Browse files
committed
Prevent crashes on non-existing assets
1 parent f73e25e commit aaa2d7f

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

app/src/main/java/com/futo/platformplayer/states/StateAssets.kt

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.futo.platformplayer.states
22

33
import android.content.Context
4+
import com.futo.platformplayer.logging.Logger
45
import kotlin.streams.asSequence
56

67
/***
@@ -45,10 +46,16 @@ class StateAssets {
4546
var text: String?;
4647
synchronized(_cache) {
4748
if (!_cache.containsKey(path)) {
48-
text = context.assets
49-
?.open(path)
50-
?.bufferedReader()
51-
?.use { it.readText(); };
49+
try {
50+
text = context.assets
51+
?.open(path)
52+
?.bufferedReader()
53+
?.use { it.readText(); };
54+
}
55+
catch(ex: Throwable) {
56+
Logger.e("StateAssets", "Could not open asset: " + path, ex);
57+
return null;
58+
}
5259

5360
_cache.put(path, text);
5461
} else {

0 commit comments

Comments
 (0)