From 5f02d9cbc54f0dd660ab779746f9580826dbc502 Mon Sep 17 00:00:00 2001 From: f1den Date: Fri, 4 Sep 2026 14:02:56 +0300 Subject: [PATCH] Fix vanilla skin texture ownership --- .../skinsg/mixin/SkinMagicMixin.java | 22 +++++++++++++++---- gradle.properties | 2 +- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/common/src/main/java/xyz/nightsync/skinsg/mixin/SkinMagicMixin.java b/common/src/main/java/xyz/nightsync/skinsg/mixin/SkinMagicMixin.java index 8522b74..478c7c8 100644 --- a/common/src/main/java/xyz/nightsync/skinsg/mixin/SkinMagicMixin.java +++ b/common/src/main/java/xyz/nightsync/skinsg/mixin/SkinMagicMixin.java @@ -22,6 +22,8 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; */ @Mixin(HttpTexture.class) public abstract class SkinMagicMixin { + private static final int VANILLA_SKIN_WIDTH = 64; + private static final int MAX_HD_SKIN_WIDTH = 2048; private static final Logger SKINSG_LOGGER = LoggerFactory.getLogger("skinsg"); @Shadow @@ -36,6 +38,14 @@ public abstract class SkinMagicMixin { final int h = image.getHeight(); final int w = image.getWidth(); + // Vanilla already owns the complete 64x32/64x64 lifecycle, including replacing and + // closing legacy images. Intercepting those images here needlessly duplicates that + // ownership path and can hand HttpTexture an already released image when another + // texture-loading mixin is present. Only HD skins belong to this mixin. + if (!skinsg$isSupportedHdSkin(w, h)) { + return; + } + final int s = w / 8; final int x64 = s * 8; final int x32 = s * 4; @@ -48,10 +58,6 @@ public abstract class SkinMagicMixin { final int x52 = x48 + x4; final int x48m4 = x48 - x4; - if (w != x64 || (h != x32 && h != x64)) { - return; - } - final boolean legacy = h == x32; if (legacy) { NativeImage newImg = new NativeImage(x64, x64, true); @@ -98,6 +104,14 @@ public abstract class SkinMagicMixin { } } + private static boolean skinsg$isSupportedHdSkin(int width, int height) { + return width > VANILLA_SKIN_WIDTH + && width <= MAX_HD_SKIN_WIDTH + && width % VANILLA_SKIN_WIDTH == 0 + && (width & (width - 1)) == 0 + && (height == width / 2 || height == width); + } + private static NativeImage skinsg$loadSteve() { try { var resource = Minecraft.getInstance().getResourceManager() diff --git a/gradle.properties b/gradle.properties index ec1bba4..5263ad4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,7 +6,7 @@ org.gradle.parallel=true # --- Mod --- mod_id=skinsg mod_name=HD Skin Support (Gravit) -mod_version=0.1.2 +mod_version=0.1.3 mod_group_id=xyz.nightsync.skinsg mod_license=All Rights Reserved mod_author=Nghtly