Allow MP updates to catch Throwable, which includes OutOfMemoryError

This commit is contained in:
yairm210 2024-11-24 10:39:01 +02:00
parent 11fb47484a
commit b09b6c92f7
6 changed files with 244 additions and 202 deletions

File diff suppressed because it is too large Load Diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 559 KiB

After

Width:  |  Height:  |  Size: 567 KiB

View File

@ -303,7 +303,7 @@ suspend fun <T> throttle(
lastSuccessfulExecution: AtomicReference<Instant?>, lastSuccessfulExecution: AtomicReference<Instant?>,
throttleInterval: Duration, throttleInterval: Duration,
onNoExecution: () -> T, onNoExecution: () -> T,
onFailed: (Exception) -> T = { throw it }, onFailed: (Throwable) -> T = { throw it },
action: suspend () -> T action: suspend () -> T
): T { ): T {
val lastExecution = lastSuccessfulExecution.get() val lastExecution = lastSuccessfulExecution.get()
@ -323,7 +323,7 @@ suspend fun <T> throttle(
suspend fun <T> attemptAction( suspend fun <T> attemptAction(
lastSuccessfulExecution: AtomicReference<Instant?>, lastSuccessfulExecution: AtomicReference<Instant?>,
onNoExecution: () -> T, onNoExecution: () -> T,
onFailed: (Exception) -> T = { throw it }, onFailed: (Throwable) -> T = { throw it },
action: suspend () -> T action: suspend () -> T
): T { ): T {
val lastExecution = lastSuccessfulExecution.get() val lastExecution = lastSuccessfulExecution.get()
@ -331,7 +331,7 @@ suspend fun <T> attemptAction(
return if (lastSuccessfulExecution.compareAndSet(lastExecution, now)) { return if (lastSuccessfulExecution.compareAndSet(lastExecution, now)) {
try { try {
action() action()
} catch (e: Exception) { } catch (e: Throwable) {
lastSuccessfulExecution.compareAndSet(now, lastExecution) lastSuccessfulExecution.compareAndSet(now, lastExecution)
onFailed(e) onFailed(e)
} }

View File

@ -41,13 +41,13 @@ class MultiplayerGame(
} }
} }
val name = fileHandle.name() val name = fileHandle.name()
var error: Exception? = null var error: Throwable? = null
init { init {
if (preview == null) { if (preview == null) {
try { try {
loadPreviewFromFile() loadPreviewFromFile()
} catch (e: Exception) { } catch (e: Throwable) {
error = e error = e
} }
} }
@ -69,9 +69,9 @@ class MultiplayerGame(
*/ */
suspend fun requestUpdate(forceUpdate: Boolean = false) = coroutineScope { suspend fun requestUpdate(forceUpdate: Boolean = false) = coroutineScope {
val onUnchanged = { GameUpdateResult(UNCHANGED, preview!!) } val onUnchanged = { GameUpdateResult(UNCHANGED, preview!!) }
val onError = { e: Exception -> val onError = { t: Throwable ->
error = e error = t
GameUpdateResult(e) GameUpdateResult(t)
} }
debug("Starting multiplayer game update for %s with id %s", name, preview?.gameId) debug("Starting multiplayer game update for %s with id %s", name, preview?.gameId)
launchOnGLThread { launchOnGLThread {
@ -145,10 +145,10 @@ class MultiplayerGame(
private class GameUpdateResult private constructor( private class GameUpdateResult private constructor(
val type: Type, val type: Type,
val status: GameInfoPreview?, val status: GameInfoPreview?,
val error: Exception? val error: Throwable?
) { ) {
constructor(type: Type, status: GameInfoPreview) : this(type, status, null) constructor(type: Type, status: GameInfoPreview) : this(type, status, null)
constructor(error: Exception) : this(FAILURE, null, error) constructor(error: Throwable) : this(FAILURE, null, error)
enum class Type { CHANGED, UNCHANGED, FAILURE } enum class Type { CHANGED, UNCHANGED, FAILURE }
} }

View File

@ -25,7 +25,7 @@ class MultiplayerGameUpdated(
*/ */
class MultiplayerGameUpdateFailed( class MultiplayerGameUpdateFailed(
override val name: String, override val name: String,
val error: Exception val error: Throwable
) : MultiplayerGameUpdateEnded ) : MultiplayerGameUpdateEnded
/** /**
* Gets sent when a game updated successfully, but nothing changed * Gets sent when a game updated successfully, but nothing changed

View File

@ -56,7 +56,7 @@ class GameList(
private class GameDisplay( private class GameDisplay(
multiplayerGameName: String, multiplayerGameName: String,
var preview: GameInfoPreview?, var preview: GameInfoPreview?,
error: Exception?, error: Throwable?,
private val onSelected: (String) -> Unit private val onSelected: (String) -> Unit
) : Table(), Comparable<GameDisplay> { ) : Table(), Comparable<GameDisplay> {
var gameName: String = multiplayerGameName var gameName: String = multiplayerGameName