{"record":{"id":"d7390b9f9481deb2","repo":"HMCL-dev/HMCL","slug":"invalid-size-width-x-height","errorCode":null,"errorMessage":"Invalid size {width}x{height}","messagePattern":"Invalid size (.+?)x(.+?)","errorType":"validation","errorClass":"InvalidSkinException","httpStatus":null,"severity":"error","filePath":"HMCLCore/src/main/java/org/jackhuang/hmcl/util/skin/NormalizedSkin.java","lineNumber":57,"sourceCode":"                int pixel = reader.getArgb(sx + x, sy + y);\n                writer.setArgb(dx + (flipHorizontal ? w - x - 1 : x), dy + y, pixel);\n            }\n        }\n    }\n\n    private final Image texture;\n    private final WritableImage normalizedTexture;\n    private final int scale;\n    private final boolean oldFormat;\n\n    public NormalizedSkin(Image texture) throws InvalidSkinException {\n        this.texture = texture;\n\n        // check format\n        int w = (int) texture.getWidth();\n        int h = (int) texture.getHeight();\n        if (w % 64 != 0) {\n            throw new InvalidSkinException(\"Invalid size \" + w + \"x\" + h);\n        }\n        if (w == h) {\n            oldFormat = false;\n        } else if (w == h * 2) {\n            oldFormat = true;\n        } else {\n            throw new InvalidSkinException(\"Invalid size \" + w + \"x\" + h);\n        }\n\n        // compute scale\n        scale = w / 64;\n\n        normalizedTexture = new WritableImage(w, w);\n        copyImage(texture, normalizedTexture, 0, 0, 0, 0, w, h, false);\n        if (oldFormat) {\n            convertOldSkin();\n        }\n    }","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/HMCL-dev/HMCL/blob/24702dc5a0214034f4c27166d5fd30cad08cec19/HMCLCore/src/main/java/org/jackhuang/hmcl/util/skin/NormalizedSkin.java#L39-L75","documentation":"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.","triggerScenarios":"Constructing a NormalizedSkin from an image whose width % 64 != 0 — e.g. a 63x63 or 100x100 texture.","commonSituations":"Users uploading hand-cropped or resized skin images; downloading skins from sources that serve nonstandard sizes; corrupted or truncated texture downloads.","solutions":["Resize/re-crop the image so width is a multiple of 64 and the aspect ratio is 1:1 (modern) or 2:1 (legacy).","Validate image dimensions before constructing NormalizedSkin and reject invalid files with a user-friendly message.","Re-download the skin from the official source, which serves standard 64x64 (or 64x32) textures.","Catch InvalidSkinException and fall back to a default skin."],"exampleFix":"// before\nNormalizedSkin skin = new NormalizedSkin(userUploadedTexture); // 100x100 -> InvalidSkinException\n// after\nif ((int) texture.getWidth() % 64 == 0) {\n    NormalizedSkin skin = new NormalizedSkin(texture);\n} else {\n    NormalizedSkin skin = new NormalizedSkin(defaultSkinTexture);\n}","handlingStrategy":"validation","validationCode":"boolean valid = (int) texture.getWidth() % 64 == 0\n    && ((int) texture.getHeight() == (int) texture.getWidth()\n        || (int) texture.getHeight() * 2 == (int) texture.getWidth());","typeGuard":"boolean isValidSkinSize(Image t) {\n    int w = (int) t.getWidth(), h = (int) t.getHeight();\n    return w % 64 == 0 && (w == h || w == h * 2);\n}","tryCatchPattern":"try {\n    skin = new NormalizedSkin(texture);\n} catch (InvalidSkinException e) {\n    skin = new NormalizedSkin(defaultSkin); // or notify user\n}","preventionTips":["Validate image dimensions before constructing NormalizedSkin.","Only load skins from trusted sources that serve 64x64/64x32 textures.","Show a user-facing message when an uploaded skin has wrong dimensions."],"tags":["skin","texture","validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"24702dc5a0214034f4c27166d5fd30cad08cec19","analyzedAt":"2026-09-10T12:36:46.680Z","contentChangedAt":"2026-09-10T12:36:46.680Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}