{"record":{"id":"c574a019f54319b6","repo":"kitao/pyxel","slug":"invalid-tile-size-in-file-path","errorCode":null,"errorMessage":"Invalid tile size in file '{path}'","messagePattern":"Invalid tile size in file '(.+?)'","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/pyxel-core/src/tmx_parser.rs","lineNumber":62,"sourceCode":"    #[serde(rename = \"tileset\", default)]\n    tilesets: Vec<Tileset>,\n    #[serde(rename = \"layer\", default)]\n    layers: Vec<Layer>,\n}\n\npub fn parse_tmx(path: &str, layer_index: u32) -> Result<RcTilemap, String> {\n    let err = |msg| format!(\"{msg} '{path}'\");\n\n    // Load and validate the TMX layer.\n    let mut file = File::open(path).map_err(|_| err(\"Failed to open file\"))?;\n    let mut tmx_text = String::new();\n    file.read_to_string(&mut tmx_text)\n        .map_err(|_| err(\"Failed to read file\"))?;\n\n    let tmx: TmxMap = serde_xml_rs::from_str(&tmx_text).map_err(|_| err(\"Failed to parse file\"))?;\n\n    if tmx.tilewidth != TILE_SIZE || tmx.tileheight != TILE_SIZE {\n        return Err(err(\"Invalid tile size in file\"));\n    }\n\n    let tileset = tmx\n        .tilesets\n        .first()\n        .ok_or_else(|| err(\"No tileset found in file\"))?;\n    let columns = tileset\n        .columns\n        .ok_or_else(|| err(\"No embedded tileset in file\"))?;\n\n    let layer = tmx\n        .layers\n        .get(layer_index as usize)\n        .ok_or_else(|| format!(\"Layer {layer_index} not found in file '{path}'\"))?;\n    if layer.data.encoding != \"csv\" {\n        return Err(err(\"Unsupported encoding in file\"));\n    }\n","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/kitao/pyxel/blob/50f9bd77780c993aca62b5b221766bde5791081d/crates/pyxel-core/src/tmx_parser.rs#L44-L80","documentation":"`parse_tmx` parsed the TMX successfully but the map's tile size does not match the library's fixed TILE_SIZE, so it rejects the file. This library only supports tilemaps whose tilewidth and tileheight equal TILE_SIZE (8 pixels in Pyxel).","triggerScenarios":"Calling `parse_tmx(path, layer_index)` on a Tiled map whose 'tilewidth' or 'tileheight' attributes differ from the engine's TILE_SIZE (e.g. 16x16 or 32x32 tiles).","commonSituations":"Creating a Tiled map with default 16px or 32px tile sizes instead of Pyxel's 8px screen-scale tiles; importing a tilemap from another engine; changing Pyxel's display scale and assuming the TMX tile size should scale too.","solutions":["Re-export/recreate the Tiled map with tile size matching TILE_SIZE (8x8).","Or set your Tiled tileset images so each tile is 8x8 pixels (scale art to 8px tiles).","Alternatively, preprocess/convert the TMX to 8x8 tiles before passing it to from_tmx.","Check the TMX header attributes `tilewidth` and `tileheight` to confirm the mismatch."],"exampleFix":"// before (map saved with tilewidth=16 tileheight=16)\nlet tilemap = Tilemap::from_tmx(\"level.tmx\", 0)?; // Invalid tile size in file 'level.tmx'\n// after: in Tiled, set Map > Tile size to 8x8 (or use an 8x8 tileset), re-save, then\nlet tilemap = Tilemap::from_tmx(\"level.tmx\", 0)?;","handlingStrategy":"validation","validationCode":"// Check TMX header tile size matches the engine's TILE_SIZE (8) before parse_tmx\nfn tmx_tile_size_ok(path: &str) -> Result<(), String> {\n    let text = std::fs::read_to_string(path).map_err(|e| e.to_string())?;\n    let width_ok = text.contains(\"tilewidth=\\\"8\\\"\");\n    let height_ok = text.contains(\"tileheight=\\\"8\\\"\");\n    if !(width_ok && height_ok) {\n        return Err(format!(\"{} must use 8x8 tiles to match Pyxel TILE_SIZE\", path));\n    }\n    Ok(())\n}","typeGuard":null,"tryCatchPattern":"match Tilemap::from_tmx(path, 0) {\n    Ok(tm) => use_tilemap(tm),\n    Err(e) if e.starts_with(\"Invalid tile size\") => {\n        eprintln!(\"{}: recreate the Tiled map with 8x8 tile size\", path);\n    }\n    Err(e) => eprintln!(\"TMX load failed: {}\", e),\n}","preventionTips":["Create Tiled maps with 8x8 tile size from the start to match Pyxel's TILE_SIZE.","Standardize on a shared 8px tileset template across the team.","Add a CI check that scans .tmx headers for tilewidth/tileheight=\"8\".","When importing maps from other engines, rescale tiles to 8x8 before loading."],"tags":["rust","validation","tmx","tilemap","tiled"],"backgroundTag":"invalid-tile-size","analyzedSha":"50f9bd77780c993aca62b5b221766bde5791081d","analyzedAt":"2026-09-03T10:27:43.285Z","contentChangedAt":"2026-09-03T10:27:43.285Z","schemaVersion":2},"datasetVersion":"2026-09-10T17:17:09.494Z"}