Improve error catching in Element.kt

This commit is contained in:
Username404-59 2021-04-22 20:28:38 +02:00
parent 4b80235049
commit b0e9747fcf
Signed by: Username404-59
GPG Key ID: 7AB361FBB257A5D1
1 changed files with 5 additions and 3 deletions

View File

@ -12,16 +12,18 @@ abstract class Element(
val width: Int, val height: Int val width: Int, val height: Int
): Renderable { ): Renderable {
companion object Rendering { companion object Rendering {
private var caughtError: Boolean = false
@JvmStatic protected val tessellator: Tesselator = Tesselator.getInstance() @JvmStatic protected val tessellator: Tesselator = Tesselator.getInstance()
@JvmStatic protected val buffer: BufferBuilder = tessellator.builder @JvmStatic protected val buffer: BufferBuilder = tessellator.builder
} }
fun display(stack: PoseStack? = null) { fun display(stack: PoseStack? = null) {
if (!hidden) try { if (!hidden && !caughtError) try {
render(stack) render(stack)
} catch (t: Throwable) { } catch (t: Throwable) {
with(Snowy.logs) { with(Snowy.logs) {
error("Caught an error when rendering an Element from SnowyGUI:") error("An element from snowy threw an error: \n$t")
catching(t) warn("Rendering of snowy UI elements will now be disabled to avoid further errors.")
caughtError = true
} }
} }
} }