diff --git a/common/src/main/java/org/embeddedt/modernfix/common/mixin/perf/faster_texture_stitching/StitcherMixin.java b/common/src/main/java/org/embeddedt/modernfix/common/mixin/perf/faster_texture_stitching/StitcherMixin.java index 5972177a..670c0169 100644 --- a/common/src/main/java/org/embeddedt/modernfix/common/mixin/perf/faster_texture_stitching/StitcherMixin.java +++ b/common/src/main/java/org/embeddedt/modernfix/common/mixin/perf/faster_texture_stitching/StitcherMixin.java @@ -1,8 +1,10 @@ package org.embeddedt.modernfix.common.mixin.perf.faster_texture_stitching; +import com.google.common.collect.ImmutableList; import com.mojang.datafixers.util.Pair; import it.unimi.dsi.fastutil.objects.ObjectArrayList; import net.minecraft.client.renderer.texture.Stitcher; +import net.minecraft.client.renderer.texture.StitcherException; import org.embeddedt.modernfix.ModernFix; import org.embeddedt.modernfix.annotation.ClientOnlyMixin; import org.embeddedt.modernfix.platform.ModernFixPlatformHooks; @@ -17,6 +19,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import java.util.Comparator; import java.util.List; import java.util.Set; +import java.util.stream.Stream; @Mixin(Stitcher.class) @ClientOnlyMixin @@ -28,6 +31,8 @@ public class StitcherMixin { @Shadow private int storageY; @Shadow @Final private static Comparator HOLDER_COMPARATOR; + @Shadow @Final private int maxWidth; + @Shadow @Final private int maxHeight; private List loadableSpriteInfos; /** @@ -48,6 +53,13 @@ public class StitcherMixin { Pair, List> packingInfo = StbStitcher.packRects(aholder); this.storageX = packingInfo.getFirst().getFirst(); this.storageY = packingInfo.getFirst().getSecond(); + + // Detect an oversized atlas generated in the previous step. + if(this.storageX > this.maxWidth || this.storageY > this.maxHeight) { + ModernFix.LOGGER.error("Requested atlas size {}x{} exceeds maximum of {}x{}", this.storageX, this.storageY, this.maxWidth, this.maxHeight); + throw new StitcherException(aholder[0].spriteInfo, Stream.of(aholder).map(arg -> arg.spriteInfo).collect(ImmutableList.toImmutableList())); + } + this.loadableSpriteInfos = packingInfo.getSecond(); }