From 4a8e0487bc8a0fd602d2b5bd83613a8ce3c4e33e Mon Sep 17 00:00:00 2001 From: embeddedt <42941056+embeddedt@users.noreply.github.com> Date: Mon, 20 Jan 2025 09:34:51 -0500 Subject: [PATCH] Prevent crash when server sends invalid palette Related: #509 --- .../perf/compact_bit_storage/PalettedContainerMixin.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/common/src/main/java/org/embeddedt/modernfix/common/mixin/perf/compact_bit_storage/PalettedContainerMixin.java b/common/src/main/java/org/embeddedt/modernfix/common/mixin/perf/compact_bit_storage/PalettedContainerMixin.java index 0a74c573..5edb5890 100644 --- a/common/src/main/java/org/embeddedt/modernfix/common/mixin/perf/compact_bit_storage/PalettedContainerMixin.java +++ b/common/src/main/java/org/embeddedt/modernfix/common/mixin/perf/compact_bit_storage/PalettedContainerMixin.java @@ -30,8 +30,15 @@ public abstract class PalettedContainerMixin { } } if(empty && storArray.length > 0) { + T value; /* it means the chunk is oversized and wasting memory, take the ID out of the palette and recreate a smaller chunk */ - T value = this.data.palette().valueFor(0); + try { + value = this.data.palette().valueFor(0); + } catch (RuntimeException e) { + // Some mods/servers seem to generate buggy palettes. This is not our fault (the game will likely crash later), + // but we catch it here to avoid receiving bug reports for an issue we didn't cause. + return; + } this.data = this.createOrReuseData(null, 0); this.data.palette().idFor(value); }