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?>,
|
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)
|
||||||
}
|
}
|
||||||
|
@ -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 }
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user