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

View File

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

View File

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

View File

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