Skip to content

Commit

Permalink
Fix NPE when rendering scenes with empty signs. (#1633)
Browse files Browse the repository at this point in the history
  • Loading branch information
leMaik authored Sep 25, 2023
1 parent 8f65154 commit 57bc68e
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions chunky/src/java/se/llbit/chunky/resources/SignTexture.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 57bc68e

Please sign in to comment.