kitao/pyxel · error
No tileset found in file '{path}'
Error message
No tileset found in file '{path}' What it means
parse_tmx found a `<map>` element with no `<tileset>` child at all. The parser requires at least one tileset because it needs `firstgid` and `columns` to convert TMX global tile IDs into Pyxel tilemap coordinates. This happens when the TMX stores tilesets in separate .tsx files (external tilesets are still emitted as `<tileset>` elements, but malformed maps or hand-written XML may omit them).
Source
Thrown at crates/pyxel-core/src/tmx_parser.rs:68
pub fn parse_tmx(path: &str, layer_index: u32) -> Result<RcTilemap, String> {
let err = |msg| format!("{msg} '{path}'");
// Load and validate the TMX layer.
let mut file = File::open(path).map_err(|_| err("Failed to open file"))?;
let mut tmx_text = String::new();
file.read_to_string(&mut tmx_text)
.map_err(|_| err("Failed to read file"))?;
let tmx: TmxMap = serde_xml_rs::from_str(&tmx_text).map_err(|_| err("Failed to parse file"))?;
if tmx.tilewidth != TILE_SIZE || tmx.tileheight != TILE_SIZE {
return Err(err("Invalid tile size in file"));
}
let tileset = tmx
.tilesets
.first()
.ok_or_else(|| err("No tileset found in file"))?;
let columns = tileset
.columns
.ok_or_else(|| err("No embedded tileset in file"))?;
let layer = tmx
.layers
.get(layer_index as usize)
.ok_or_else(|| format!("Layer {layer_index} not found in file '{path}'"))?;
if layer.data.encoding != "csv" {
return Err(err("Unsupported encoding in file"));
}
let tile_ids: Vec<u32> = remove_whitespace(&layer.data.tiles)
.split(',')
.map(|s| s.parse::<u32>().map_err(|_| err("Failed to parse file")))
.collect::<Result<_, _>>()?;
// Convert TMX global tile IDs into Pyxel image tile coordinates.View on GitHub (pinned to 50f9bd7778)
Solutions
- Open the TMX file and confirm the <map> contains at least one <tileset firstgid=...> element
- Re-export the map from Tiled with the tileset embedded in the .tmx file
- If the tileset is external (.tsx), inline it or pre-process the XML to insert the tileset element before calling parse_tmx
- Validate the TMX against the Tiled DTD/schema to catch missing required elements
Example fix
// before: map with no tileset <map version="1.10" tilewidth="16" tileheight="16"> <layer .../> </map> // after: embed the tileset <map version="1.10" tilewidth="16" tileheight="16"> <tileset firstgid="1" name="tiles" tilewidth="16" tileheight="16" columns="8"/> <layer .../> </map>
Defensive patterns
Strategy: validation
Validate before calling
fn has_tileset(tmx_path: &str) -> std::io::Result<bool> {
let xml = std::fs::read_to_string(tmx_path)?;
Ok(xml.contains("<tileset"))
}
if !has_tileset(path)? {
eprintln!("{path}: embed a <tileset> in the TMX before parsing");
} Prevention
- Export maps from Tiled with tilesets embedded in the .tmx
- Add a CI check that every .tmx contains a <tileset> element
- Never hand-strip tileset elements from exported maps
When it happens
Trigger: Calling parse_tmx(path, layer_index) (directly or via from_tmx) on a TMX file whose `<map>` element contains zero `<tileset>` entries — tmx.tilesets.first() returns None.
Common situations: Hand-authored or programmatically generated TMX without a tileset element; a map that only references tilesets through objects/image layers stripped out by the deserializer; exporting from a tool with 'embed tilesets' disabled combined with post-processing that removed the tileset tags.
Related errors
- No embedded tileset in file '{path}'
- Unsupported encoding in file '{path}'
- Failed to open file '{path}'
- Failed to read file '{path}'
- Failed to parse file '{path}'
AI-assisted analysis of kitao/pyxel@50f9bd7778 (2026-09-03).
Data as JSON: /api/errors/337ddc59c782971a.
Report an issue: GitHub.