From aaa2d7f08d3017bb592dde3b9d92d0da4fe96f95 Mon Sep 17 00:00:00 2001 From: Kelvin Date: Thu, 19 Dec 2024 22:00:56 +0100 Subject: [PATCH] Prevent crashes on non-existing assets --- .../com/futo/platformplayer/states/StateAssets.kt | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/futo/platformplayer/states/StateAssets.kt b/app/src/main/java/com/futo/platformplayer/states/StateAssets.kt index 605ea928..b4af2f61 100644 --- a/app/src/main/java/com/futo/platformplayer/states/StateAssets.kt +++ b/app/src/main/java/com/futo/platformplayer/states/StateAssets.kt @@ -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 {