mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-27 05:46:43 -04:00
Hopefully solved ANRs when first entering a large multiplayer game
This commit is contained in:
parent
3ef34f99ff
commit
707b59cc6a
@ -17,6 +17,7 @@ import com.unciv.ui.utils.toLabel
|
|||||||
import com.unciv.ui.worldscreen.WorldScreen
|
import com.unciv.ui.worldscreen.WorldScreen
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.collections.ArrayList
|
import kotlin.collections.ArrayList
|
||||||
|
import kotlin.concurrent.thread
|
||||||
|
|
||||||
class WorldScreenMenuTable(val worldScreen: WorldScreen) : PopupTable(worldScreen) {
|
class WorldScreenMenuTable(val worldScreen: WorldScreen) : PopupTable(worldScreen) {
|
||||||
|
|
||||||
@ -117,13 +118,18 @@ class WorldScreenMenuTable(val worldScreen: WorldScreen) : PopupTable(worldScree
|
|||||||
badGameIdLabel.isVisible = true
|
badGameIdLabel.isVisible = true
|
||||||
return@addButton
|
return@addButton
|
||||||
}
|
}
|
||||||
|
thread {
|
||||||
try {
|
try {
|
||||||
|
// The tryDownload can take more than 500ms. Therefore, to avoid ANRs,
|
||||||
|
// we need to run it in a different thread.
|
||||||
val game = OnlineMultiplayer().tryDownloadGame(gameId.trim())
|
val game = OnlineMultiplayer().tryDownloadGame(gameId.trim())
|
||||||
UncivGame.Current.loadGame(game)
|
// The loadGame creates a screen, so it's a UI action,
|
||||||
|
// therefore it needs to run on the main thread so it has a GL context
|
||||||
|
Gdx.app.postRunnable { UncivGame.Current.loadGame(game) }
|
||||||
} catch (ex: Exception) {
|
} catch (ex: Exception) {
|
||||||
badGameIdLabel.setText("Could not download game!".tr())
|
badGameIdLabel.setText("Could not download game!".tr())
|
||||||
badGameIdLabel.isVisible = true
|
badGameIdLabel.isVisible = true
|
||||||
return@addButton
|
}
|
||||||
}
|
}
|
||||||
}.row()
|
}.row()
|
||||||
multiplayerPopup.add(badGameIdLabel).row()
|
multiplayerPopup.add(badGameIdLabel).row()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user