{"record":{"id":"246eb9914b345a4e","repo":"FyroxEngine/Fyrox","slug":"height-data-type-error","errorCode":null,"errorMessage":"Height data type error: {:?}","messagePattern":"Height data type error: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"fyrox-impl/src/scene/terrain/mod.rs","lineNumber":216,"sourceCode":"    }\n    #[inline]\n    fn is_valid_index(&self, position: Vector2<i32>) -> bool {\n        let s = self.size();\n        (-1..=s.x as i32).contains(&position.x) && (-1..=s.y as i32).contains(&position.y)\n    }\n}\n\nimpl std::ops::Index<Vector2<i32>> for ChunkHeightData<'_> {\n    type Output = f32;\n\n    fn index(&self, position: Vector2<i32>) -> &Self::Output {\n        assert!(self.is_valid_index(position));\n        let row_size = self.row_size();\n        let x = (position.x + 1) as usize;\n        let y = (position.y + 1) as usize;\n        match self.0.data_of_type::<f32>() {\n            Some(d) => &d[y * row_size + x],\n            None => panic!(\"Height data type error: {:?}\", self.0),\n        }\n    }\n}\nimpl std::ops::Index<Vector2<i32>> for ChunkHeightMutData<'_> {\n    type Output = f32;\n\n    fn index(&self, position: Vector2<i32>) -> &Self::Output {\n        assert!(self.is_valid_index(position));\n        let row_size = self.row_size();\n        let x = (position.x + 1) as usize;\n        let y = (position.y + 1) as usize;\n        &self.0.data_of_type::<f32>().unwrap()[y * row_size + x]\n    }\n}\nimpl std::ops::IndexMut<Vector2<i32>> for ChunkHeightMutData<'_> {\n    fn index_mut(&mut self, position: Vector2<i32>) -> &mut Self::Output {\n        assert!(self.is_valid_index(position));\n        let row_size = self.row_size();","sourceCodeStart":198,"sourceCodeEnd":234,"githubUrl":"https://github.com/FyroxEngine/Fyrox/blob/76c91aad8eca488ce527b1af707be8b3b24ad72d/fyrox-impl/src/scene/terrain/mod.rs#L198-L234","documentation":"The Index impl for ChunkHeightMutData reads height values as f32 via Texture::data_of_type::<f32>(). When the heightmap texture's pixel data is not stored as f32 (wrong TexturePixelKind), data_of_type returns None and the code panics with \"Height data type error\" including the texture debug output. Terrain heightmaps must internally be f32 pixel data.","triggerScenarios":"Indexing ChunkHeightMutData when the heightmap texture was created with a non-f32 pixel format (e.g. RGBA8, R8), typically by replacing the chunk heightmap with a hand-built texture instead of make_height_map_texture.","commonSituations":"Importing a heightmap from an image file (PNG/JPG yields u8 RGBA data) directly as terrain heightmap; custom terrain generation pipelines that forget to convert pixel data to f32; scene assets edited externally.","solutions":["Create the heightmap texture via make_height_map_texture / the terrain API so pixel data is f32 (correct TexturePixelKind).","If importing an image, convert its pixels to f32 first (e.g. normalize u8 to 0.0..1.0) and build the texture with an f32 pixel kind.","Check texture.data_ref().data_of_type::<f32>().is_some() before indexing and regenerate the heightmap if None.","Keep using the public height-map editing APIs which guarantee the f32 representation."],"exampleFix":"// before\nlet img = image::open(\"height.png\").unwrap();\nlet tex = Texture::from_pixels(w, h, TexturePixelKind::RGBA8, img.into_raw());\nchunk.set_height_map(tex);\nlet v = chunk.height_data_mut()[pos]; // panics: not f32\n// after\nlet heights: Vec<f32> = img.pixels().map(|p| p[0] as f32 / 255.0).collect();\nlet tex = make_height_map_texture(heights, size);\nchunk.set_height_map(tex);","handlingStrategy":"validation","validationCode":"let data = chunk.height_map().unwrap().data_ref();\nassert!(data.data_of_type::<f32>().is_some(), \"terrain heightmap must contain f32 pixel data\");","typeGuard":"fn is_f32_heightmap(tex: &TextureResource) -> bool {\n    tex.data_ref().data_of_type::<f32>().is_some()\n}","tryCatchPattern":"// Guard rather than catch: check dtype before indexing\nif is_f32_heightmap(&chunk.height_map().unwrap()) {\n    let v = chunk.height_data_mut()[pos];\n} else {\n    // rebuild heightmap as f32\n}","preventionTips":["Convert imported height images to f32 (value / 255.0) before building the heightmap texture.","Use make_height_map_texture so the pixel kind is the f32 terrain format.","Never attach RGBA8/R8 textures as terrain heightmaps.","Check data_of_type::<f32>() once after any texture assignment."],"tags":["panic","dtype","texture","terrain","rust"],"backgroundTag":"dtype-mismatch","analyzedSha":"76c91aad8eca488ce527b1af707be8b3b24ad72d","analyzedAt":"2026-09-10T16:04:01.633Z","contentChangedAt":"2026-09-10T16:04:01.633Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}