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
): 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
}
}
}