{"record":{"id":"46b79d53c8913051","repo":"CoplayDev/unity-mcp","slug":"width-and-height-must-be-positive","errorCode":null,"errorMessage":"width and height must be positive","messagePattern":"width and height must be positive","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"Server/src/cli/commands/texture.py","lineNumber":64,"sourceCode":"    \"low_quality\": \"CompressedLQ\",\n    \"normal_quality\": \"Compressed\",\n    \"high_quality\": \"CompressedHQ\",\n}\n\n_SPRITE_MODES = {\"single\": \"Single\",\n                 \"multiple\": \"Multiple\", \"polygon\": \"Polygon\"}\n\n_SPRITE_MESH_TYPES = {\"full_rect\": \"FullRect\", \"tight\": \"Tight\"}\n\n_MIPMAP_FILTERS = {\"box\": \"BoxFilter\", \"kaiser\": \"KaiserFilter\"}\n\n_MAX_TEXTURE_DIMENSION = 1024\n_MAX_TEXTURE_PIXELS = 1024 * 1024\n\n\ndef _validate_texture_dimensions(width: int, height: int) -> list[str]:\n    if width <= 0 or height <= 0:\n        raise ValueError(\"width and height must be positive\")\n    warnings: list[str] = []\n    if width > _MAX_TEXTURE_DIMENSION or height > _MAX_TEXTURE_DIMENSION:\n        warnings.append(\n            f\"width and height should be <= {_MAX_TEXTURE_DIMENSION} (got {width}x{height})\")\n    total_pixels = width * height\n    if total_pixels > _MAX_TEXTURE_PIXELS:\n        warnings.append(\n            f\"width*height should be <= {_MAX_TEXTURE_PIXELS} (got {width}x{height})\")\n    return warnings\n\n\ndef _is_normalized_color(values: list[Any]) -> bool:\n    if not values:\n        return False\n\n    try:\n        numeric_values = [float(v) for v in values]\n    except (TypeError, ValueError):","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/CoplayDev/unity-mcp/blob/c21bf496bca87d54e75bad048563c3adb1782081/Server/src/cli/commands/texture.py#L46-L82","documentation":"Raised by _validate_texture_dimensions (texture.py:64) when width or height is <= 0. The function validates the --width/--height options of the `texture create` and `texture sprite` CLI commands before they are sent to Unity as the new Texture2D dimensions. The CLI handlers wrap the call in try/except ValueError and exit(1) on failure, so the user sees the message and a non-zero exit code. (Separately, the same function emits soft warnings when dimensions exceed 1024 or total pixels exceed 1,048,576.)","triggerScenarios":"Running `unity-mcp texture create <path> --width 0` (or negative), or `--height 0`, or omitting them in a context where they resolve to <= 0 (note Click defaults them to 64, so you must pass an explicit non-positive value). Triggered only on the create/sprite commands, not when --image-path is used (that branch skips dimension validation).","commonSituations":"Passing `--width 0` or `--width -1`; a script computing width/height that underflows to 0; copy-pasting a command with a typo'd negative number.","solutions":["Pass positive integers for --width and --height (e.g. --width 64 --height 64).","If dimensions come from a script, clamp them to a minimum of 1 before invoking the CLI.","Drop --width/--height to accept the default 64 when you have no specific size requirement."],"exampleFix":"# before\nunity-mcp texture create Assets/Tex.png --width 0 --height 64\n\n# after\nunity-mcp texture create Assets/Tex.png --width 64 --height 64","handlingStrategy":"validation","validationCode":"# Python - before calling the CLI / _validate_texture_dimensions\nif not isinstance(width, int) or not isinstance(height, int) or width <= 0 or height <= 0:\n    raise SystemExit(f\"width and height must be positive (got {width}x{height})\")","typeGuard":"def is_positive_int(v) -> bool: return isinstance(v, int) and not isinstance(v, bool) and v > 0","tryCatchPattern":"try:\n    warnings = _validate_texture_dimensions(width, height)\nexcept ValueError as e:\n    print_error(str(e)); sys.exit(1)","preventionTips":["Clamp script-computed dimensions to a minimum of 1.","Let --width/--height default to 64 when you have no specific size."],"tags":["python","cli","texture","validation","value-error"],"backgroundTag":null,"analyzedSha":"c21bf496bca87d54e75bad048563c3adb1782081","analyzedAt":"2026-08-13T17:36:56.095Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}