Skip to content

Commit

Permalink
Prevent crashes on non-existing assets
Browse files Browse the repository at this point in the history
  • Loading branch information
Kelvin-FUTO committed Dec 19, 2024
1 parent f73e25e commit aaa2d7f
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions app/src/main/java/com/futo/platformplayer/states/StateAssets.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.futo.platformplayer.states

import android.content.Context
import com.futo.platformplayer.logging.Logger
import kotlin.streams.asSequence

/***
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit aaa2d7f

Please sign in to comment.