From ad3fb8be7a0abb571f6cec792775d4167c808df4 Mon Sep 17 00:00:00 2001 From: Username404-59 Date: Mon, 12 Apr 2021 23:44:15 +0200 Subject: [PATCH] Add a try and catch in the render function of ClickBox.kt. --- .../fr/username404/snowygui/gui/ClickBox.kt | 37 +++++++++++-------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/common/src/main/kotlin/fr/username404/snowygui/gui/ClickBox.kt b/common/src/main/kotlin/fr/username404/snowygui/gui/ClickBox.kt index 00b6253..c69daf0 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/gui/ClickBox.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/gui/ClickBox.kt @@ -3,6 +3,7 @@ package fr.username404.snowygui.gui import com.mojang.blaze3d.systems.RenderSystem import com.mojang.blaze3d.vertex.DefaultVertexFormat import com.mojang.blaze3d.vertex.PoseStack +import fr.username404.snowygui.Snowy import net.minecraft.client.Minecraft import net.minecraft.network.chat.TranslatableComponent import org.lwjgl.opengl.GL20 @@ -16,24 +17,28 @@ class ClickBox(x: Double, y: Double, private val name: TranslatableComponent? = RenderSystem.enableBlend() RenderSystem.defaultBlendFunc() with(buffer) { - begin(GL20.GL_POLYGON, DefaultVertexFormat.POSITION_COLOR) - // Render the header: - vertex(x, y + height, 0.0).colorEnd() - vertex(x + width + inclination, y + height, 0.0).colorEnd() - vertex(x + width, y, 0.0).colorEnd() - vertex(x + inclination, y, 0.0).colorEnd() + try { + begin(GL20.GL_POLYGON, DefaultVertexFormat.POSITION_COLOR) + // Render the header: + vertex(x, y + height, 0.0).colorEnd() + vertex(x + width + inclination, y + height, 0.0).colorEnd() + vertex(x + width, y, 0.0).colorEnd() + vertex(x + inclination, y, 0.0).colorEnd() - // Render the box: - val fullHeight = (y + height) + 80 - vertex(x, fullHeight, 0.0).colorEnd() - vertex(x + width + inclination, fullHeight, 0.0).colorEnd() - vertex(x + width + inclination, y + height, 0.0).colorEnd() - tessellator.end() + // Render the box: + val fullHeight = (y + height) + 80 + vertex(x, fullHeight, 0.0).colorEnd() + vertex(x + width + inclination, fullHeight, 0.0).colorEnd() + vertex(x + width + inclination, y + height, 0.0).colorEnd() + tessellator.end() - begin(GL20.GL_LINES, DefaultVertexFormat.POSITION_COLOR) - vertex(x + inclination, y + height, 0.0).colorIt(0xF2F2FC).endVertex() - vertex(x + width, y + height, 0.0).colorIt(0xF2F2FC).endVertex() - tessellator.end() + begin(GL20.GL_LINES, DefaultVertexFormat.POSITION_COLOR) + vertex(x + inclination, y + height, 0.0).colorIt(0xF2F2FC).endVertex() + vertex(x + width, y + height, 0.0).colorIt(0xF2F2FC).endVertex() + tessellator.end() + } catch (e: Error) { + Snowy.logs.error("Error caught when rendering a ClickBox: $e") + } } RenderSystem.enableTexture() RenderSystem.disableBlend()