From b0e9747fcf1fec77a1a2dfc547d4b6df5132f152 Mon Sep 17 00:00:00 2001 From: Username404-59 Date: Thu, 22 Apr 2021 20:28:38 +0200 Subject: [PATCH] Improve error catching in Element.kt --- .../main/kotlin/fr/username404/snowygui/gui/Element.kt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/common/src/main/kotlin/fr/username404/snowygui/gui/Element.kt b/common/src/main/kotlin/fr/username404/snowygui/gui/Element.kt index 82dfbe4..cfa9e86 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/gui/Element.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/gui/Element.kt @@ -12,16 +12,18 @@ abstract class Element( val width: Int, val height: Int ): Renderable { companion object Rendering { + private var caughtError: Boolean = false @JvmStatic protected val tessellator: Tesselator = Tesselator.getInstance() @JvmStatic protected val buffer: BufferBuilder = tessellator.builder } fun display(stack: PoseStack? = null) { - if (!hidden) try { + if (!hidden && !caughtError) try { render(stack) } catch (t: Throwable) { with(Snowy.logs) { - error("Caught an error when rendering an Element from SnowyGUI:") - catching(t) + error("An element from snowy threw an error: \n$t") + warn("Rendering of snowy UI elements will now be disabled to avoid further errors.") + caughtError = true } } }