HMCL-dev/HMCL · error · InvalidSkinException

Invalid size x

Error message

Invalid size {width}x{height}

What it means

NormalizedSkin's constructor validates the skin texture dimensions and throws InvalidSkinException 'Invalid size WxH' if the width is not a multiple of 64 pixels. Skins must be 64-based (e.g. 64x32, 64x64, 128x128) to be normalizable.

Solutions

  1. Resize/re-crop the image so width is a multiple of 64 and the aspect ratio is 1:1 (modern) or 2:1 (legacy).
  2. Validate image dimensions before constructing NormalizedSkin and reject invalid files with a user-friendly message.
  3. Re-download the skin from the official source, which serves standard 64x64 (or 64x32) textures.
  4. Catch InvalidSkinException and fall back to a default skin.

Example fix

// before
NormalizedSkin skin = new NormalizedSkin(userUploadedTexture); // 100x100 -> InvalidSkinException
// after
if ((int) texture.getWidth() % 64 == 0) {
    NormalizedSkin skin = new NormalizedSkin(texture);
} else {
    NormalizedSkin skin = new NormalizedSkin(defaultSkinTexture);
}
Defensive patterns

Strategy: validation

Validate before calling

boolean valid = (int) texture.getWidth() % 64 == 0
    && ((int) texture.getHeight() == (int) texture.getWidth()
        || (int) texture.getHeight() * 2 == (int) texture.getWidth());

Type guard

boolean isValidSkinSize(Image t) {
    int w = (int) t.getWidth(), h = (int) t.getHeight();
    return w % 64 == 0 && (w == h || w == h * 2);
}

Try / catch

try {
    skin = new NormalizedSkin(texture);
} catch (InvalidSkinException e) {
    skin = new NormalizedSkin(defaultSkin); // or notify user
}

Prevention

When it happens

Trigger: Constructing a NormalizedSkin from an image whose width % 64 != 0 — e.g. a 63x63 or 100x100 texture.

Common situations: Users uploading hand-cropped or resized skin images; downloading skins from sources that serve nonstandard sizes; corrupted or truncated texture downloads.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of HMCL-dev/HMCL@24702dc5a0 (2026-09-10). Data as JSON: /api/errors/d7390b9f9481deb2. Report an issue: GitHub.

Appendix: source

Thrown at HMCLCore/src/main/java/org/jackhuang/hmcl/util/skin/NormalizedSkin.java:57

                int pixel = reader.getArgb(sx + x, sy + y);
                writer.setArgb(dx + (flipHorizontal ? w - x - 1 : x), dy + y, pixel);
            }
        }
    }

    private final Image texture;
    private final WritableImage normalizedTexture;
    private final int scale;
    private final boolean oldFormat;

    public NormalizedSkin(Image texture) throws InvalidSkinException {
        this.texture = texture;

        // check format
        int w = (int) texture.getWidth();
        int h = (int) texture.getHeight();
        if (w % 64 != 0) {
            throw new InvalidSkinException("Invalid size " + w + "x" + h);
        }
        if (w == h) {
            oldFormat = false;
        } else if (w == h * 2) {
            oldFormat = true;
        } else {
            throw new InvalidSkinException("Invalid size " + w + "x" + h);
        }

        // compute scale
        scale = w / 64;

        normalizedTexture = new WritableImage(w, w);
        copyImage(texture, normalizedTexture, 0, 0, 0, 0, w, h, false);
        if (oldFormat) {
            convertOldSkin();
        }
    }

View on GitHub (pinned to 24702dc5a0)