From 64cfa1529a3767ad365ab0290fd410e003f6bfd3 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Thu, 16 Dec 2021 23:23:11 +0900 Subject: [PATCH] fixed a bug where destroying the world while F3 is on would cause a NullPointerException --- .../terrarum/serialise/WriteSavegame.kt | 6 ++++- .../terrarum/ui/BasicDebugInfoWindow.kt | 26 +++++++++---------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/net/torvald/terrarum/serialise/WriteSavegame.kt b/src/net/torvald/terrarum/serialise/WriteSavegame.kt index 1aaf1906e..75c99d6a0 100644 --- a/src/net/torvald/terrarum/serialise/WriteSavegame.kt +++ b/src/net/torvald/terrarum/serialise/WriteSavegame.kt @@ -51,7 +51,11 @@ object WriteSavegame { val w = 960 val h = 640 - val p = Pixmap.createFromFrameBuffer((it.width - w).ushr(1), (it.height - h).ushr(1), w, h) + + val x = (it.width - w).ushr(2).shl(1) // force the even-numbered position + val y = (it.height - h).ushr(2).shl(1) // force the even-numbered position + + val p = Pixmap.createFromFrameBuffer(x, y, w, h) IngameRenderer.fboRGBexport = p //PixmapIO2._writeTGA(gzout, p, true, true) //p.dispose() diff --git a/src/net/torvald/terrarum/ui/BasicDebugInfoWindow.kt b/src/net/torvald/terrarum/ui/BasicDebugInfoWindow.kt index a4bc0387f..34128e965 100644 --- a/src/net/torvald/terrarum/ui/BasicDebugInfoWindow.kt +++ b/src/net/torvald/terrarum/ui/BasicDebugInfoWindow.kt @@ -155,18 +155,23 @@ class BasicDebugInfoWindow : UICanvas() { else "$rawR $rawG $rawB $rawA" printLine(batch, 8, "light@cursor $ccG$lightVal") - if (ingame != null) { - val wallNum = ingame!!.world.getTileFromWall(mouseTileX, mouseTileY) - val tileNum = ingame!!.world.getTileFromTerrain(mouseTileX, mouseTileY) - val wires = ingame!!.world.getAllWiresFrom(mouseTileX, mouseTileY) - val fluid = ingame!!.world.getFluid(mouseTileX, mouseTileY) + try { + world?.let { + val wallNum = it.getTileFromWall(mouseTileX, mouseTileY) + val tileNum = it.getTileFromTerrain(mouseTileX, mouseTileY) + val wires = it.getAllWiresFrom(mouseTileX, mouseTileY) + val fluid = it.getFluid(mouseTileX, mouseTileY) - val wireCount = wires?.size?.toString() ?: "no" + val wireCount = wires?.size?.toString() ?: "no" - printLine(batch, 9, "tile@cursor ${ccO}W$ccG$wallNum ${ccO}T$ccG$tileNum ${ccO}C$ccG($wireCount wires) $ccY($mtX,$mtY;$ccO${LandUtil.getBlockAddr(ingame!!.world, mouseTileX, mouseTileY)}$ccY)") - printLine(batch, 10, "fluid@cursor ${ccO}Type $ccG${fluid.type.value} ${ccO}Fill $ccG${fluid.amount}f") + printLine(batch, 9, "tile@cursor ${ccO}W$ccG$wallNum ${ccO}T$ccG$tileNum ${ccO}C$ccG($wireCount wires) $ccY($mtX,$mtY;$ccO${LandUtil.getBlockAddr(it, mouseTileX, mouseTileY)}$ccY)") + printLine(batch, 10, "fluid@cursor ${ccO}Type $ccG${fluid.type.value} ${ccO}Fill $ccG${fluid.amount}f") + printLineColumn(batch, 2, 5, "Time $ccG${it.worldTime.todaySeconds.toString().padStart(5, '0')}" + + " (${it.worldTime.getFormattedTime()})") + } } + catch (e: NullPointerException) {} // print time @@ -184,11 +189,6 @@ class BasicDebugInfoWindow : UICanvas() { //printLineColumn(batch, 2, 1, "VSync $ccG" + Terrarum.appgc.isVSyncRequested) //printLineColumn(batch, 2, 2, "Env colour temp $ccG" + FeaturesDrawer.colTemp) - if (world != null) { - printLineColumn(batch, 2, 5, "Time $ccG${world?.worldTime?.todaySeconds.toString().padStart(5, '0')}" + - " (${world?.worldTime?.getFormattedTime()})") - } - if (player != null) { printLineColumn(batch, 2, 6, "Mass $ccG${player.mass}")