mirror of
https://github.com/yairm210/Unciv.git
synced 2025-01-31 18:04:55 +07:00
Allow MP updates to catch Throwable, which includes OutOfMemoryError
This commit is contained in:
parent
11fb47484a
commit
b09b6c92f7
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 |
@ -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)
|
||||
}
|
||||
|
@ -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 }
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user