{"record":{"id":"8b0fc222d03e2aec","repo":"kitao/pyxel","slug":"tilemap-dimensions-are-too-large","errorCode":null,"errorMessage":"tilemap dimensions are too large","messagePattern":"tilemap dimensions are too large","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/pyxel-core/src/tilemap.rs","lineNumber":46,"sourceCode":"            ImageSource::Index(index) => crate::pyxel::images()[*index as usize].clone(),\n            ImageSource::Image(image) => image.clone(),\n        }\n    }\n}\n\n#[derive(Clone)]\npub struct Tilemap {\n    pub imgsrc: ImageSource,\n    pub(crate) canvas: Canvas<Tile>,\n}\n\ndefine_rc_type!(RcTilemap, Tilemap);\n\nimpl Tilemap {\n    // Constructors\n\n    pub fn new(width: u32, height: u32, imgsrc: ImageSource) -> RcTilemap {\n        Self::try_new(width, height, imgsrc).expect(\"tilemap dimensions are too large\")\n    }\n\n    pub fn try_new(width: u32, height: u32, imgsrc: ImageSource) -> Result<RcTilemap, String> {\n        let canvas = Canvas::try_new(width, height)\n            .ok_or_else(|| \"tilemap dimensions are too large\".to_string())?;\n        Ok(new_rc_type!(Self { imgsrc, canvas }))\n    }\n\n    pub fn from_tmx(filename: &str, layer_index: u32) -> Result<RcTilemap, String> {\n        parse_tmx(filename, layer_index)\n    }\n\n    // Public accessors\n\n    pub const fn width(&self) -> u32 {\n        self.canvas.width()\n    }\n","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/kitao/pyxel/blob/50f9bd77780c993aca62b5b221766bde5791081d/crates/pyxel-core/src/tilemap.rs#L28-L64","documentation":"`Tilemap::new` builds an internal Canvas sized width*height tiles; if that canvas cannot be created (checked multiplication overflow / size limit), try_new returns Err and `new` panics with 'tilemap dimensions are too large'.","triggerScenarios":"Calling Tilemap::new(width, height, imgsrc) with a width*height tile count exceeding the canvas limit, or constructing tilemaps from resources whose declared dimensions are impossible.","commonSituations":"Corrupted or hand-edited .tmx/resource files with bogus dimensions; generating procedural tilemaps from unbounded user input; misreading the API as expecting pixels rather than tiles (or vice versa) leading to huge numbers.","solutions":["Use Tilemap::try_new and handle the Err instead of panicking.","Validate/clamp tilemap width and height before construction.","Fix the source data (resource file dimensions) if it declares oversized maps."],"exampleFix":"// before\nlet tm = Tilemap::new(w, h, imgsrc);\n// after\nlet tm = Tilemap::try_new(w, h, imgsrc).map_err(|e| format!(\"cannot create tilemap: {e}\"))?;","handlingStrategy":"validation","validationCode":"fn valid_tilemap_dims(w: u32, h: u32) -> bool {\n    w.checked_mul(h).is_some()\n}","typeGuard":null,"tryCatchPattern":"// use the fallible API instead of catching the panic\nmatch Tilemap::try_new(w, h, imgsrc) {\n    Ok(tm) => tm,\n    Err(msg) => { /* log and use a smaller default tilemap */ }\n}","preventionTips":["Prefer Tilemap::try_new over Tilemap::new for dynamic or untrusted dimensions.","Validate tilemap dimensions in resource files before loading.","Clamp procedurally generated map sizes to a safe maximum."],"tags":["rust","panic","tilemap","canvas"],"backgroundTag":"dimensions-too-large","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"}