Harden map editor map loader against most bad maps (#4711)

* Harden map editor map loader against most bad maps

* Harden map editor map loader against most bad maps - patch1
This commit is contained in:
SomeTroglodyte 2021-08-02 18:03:16 +02:00 committed by GitHub
parent 5511c80eb5
commit 7d52cfbcab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 9 deletions

View File

@ -879,6 +879,7 @@ Clear current map =
Save map =
Download map =
Loading... =
Error loading map! =
Filter: =
OK =
Exit map editor =

View File

@ -10,6 +10,7 @@ import com.badlogic.gdx.utils.Json
import com.unciv.logic.MapSaver
import com.unciv.logic.map.MapType
import com.unciv.logic.map.TileMap
import com.unciv.models.ruleset.RulesetCache
import com.unciv.models.translations.tr
import com.unciv.ui.pickerscreens.PickerScreen
import com.unciv.ui.saves.Gzip
@ -54,17 +55,45 @@ class SaveAndLoadMapScreen(mapToSave: TileMap?, save:Boolean = false, previousSc
} else {
rightSideButton.setText("Load map".tr())
rightSideButtonAction = {
thread {
thread(name = "MapLoader") {
var popup: Popup? = null
var needPopup = true // loadMap can fail faster than postRunnable runs
Gdx.app.postRunnable {
val popup = Popup(this)
popup.addGoodSizedLabel("Loading...")
popup.open()
if (!needPopup) return@postRunnable
popup = Popup(this).apply {
addGoodSizedLabel("Loading...")
open()
}
}
val map = MapSaver.loadMap(chosenMap!!)
Gdx.app.postRunnable {
Gdx.input.inputProcessor = null // This is to stop ANRs happening here, until the map editor screen sets up.
game.setScreen(MapEditorScreen(map))
dispose()
try {
val map = MapSaver.loadMap(chosenMap!!)
val missingMods = map.mapParameters.mods.filter { it !in RulesetCache }
if (missingMods.isNotEmpty()) {
Gdx.app.postRunnable {
needPopup = false
popup?.close()
ToastPopup("Missing mods: [${missingMods.joinToString()}]", this)
}
} else Gdx.app.postRunnable {
Gdx.input.inputProcessor = null // This is to stop ANRs happening here, until the map editor screen sets up.
try {
game.setScreen(MapEditorScreen(map))
dispose()
} catch (ex: Throwable) {
needPopup = false
popup?.close()
println("Error displaying map \"$chosenMap\": ${ex.localizedMessage}")
Gdx.input.inputProcessor = stage
ToastPopup("Error loading map!", this)
}
}
} catch (ex: Throwable) {
needPopup = false
Gdx.app.postRunnable {
popup?.close()
println("Error loading map \"$chosenMap\": ${ex.localizedMessage}")
ToastPopup("Error loading map!", this)
}
}
}
}