From 57bc68e6e2f178c68c625c1ed2e7d4e978ba9060 Mon Sep 17 00:00:00 2001 From: Maik Marschner Date: Tue, 26 Sep 2023 00:53:32 +0200 Subject: [PATCH] Fix NPE when rendering scenes with empty signs. (#1633) --- .../llbit/chunky/resources/SignTexture.java | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/chunky/src/java/se/llbit/chunky/resources/SignTexture.java b/chunky/src/java/se/llbit/chunky/resources/SignTexture.java index f56a6bd3b4..0a3e8f10a1 100644 --- a/chunky/src/java/se/llbit/chunky/resources/SignTexture.java +++ b/chunky/src/java/se/llbit/chunky/resources/SignTexture.java @@ -20,14 +20,15 @@ import se.llbit.chunky.resources.texturepack.FontTexture.Glyph; import se.llbit.json.JsonArray; import se.llbit.json.JsonValue; -import se.llbit.math.ColorUtil; import se.llbit.math.Ray; -import se.llbit.math.Vector4; +import se.llbit.util.annotation.Nullable; public class SignTexture extends Texture { private final double hh, ww, u0, v0; private final Texture signTexture; + @Nullable private final PalettizedBitmapImage textColor; + @Nullable private final BinaryBitmapImage textMask; static private boolean hasVisibleCharacter(JsonArray line) { @@ -107,13 +108,14 @@ public SignTexture(JsonArray[] text, Texture signTexture, int signWidth, int sig @Override public float[] getColor(double u, double v) { - int x = (int) (u * textColor.width - Ray.EPSILON); - int y = (int) ((1 - v) * textColor.height - Ray.EPSILON); - if (textMask != null && textMask.getPixel(x, y)) { - Color characterColor = Color.get(textColor.getPixel(x, y)); - return characterColor.linearColor; - } else { - return signTexture.getColor(u * ww + u0, v * hh + v0); + if (textColor != null) { + int x = (int) (u * textColor.width - Ray.EPSILON); + int y = (int) ((1 - v) * textColor.height - Ray.EPSILON); + if (textMask != null && textMask.getPixel(x, y)) { + Color characterColor = Color.get(textColor.getPixel(x, y)); + return characterColor.linearColor; + } } + return signTexture.getColor(u * ww + u0, v * hh + v0); } }