{"record":{"id":"fcfc9566342e503a","repo":"FyroxEngine/Fyrox","slug":"invalid-texture-kind","errorCode":null,"errorMessage":"Invalid texture kind.","messagePattern":"Invalid texture kind\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"fyrox-impl/src/scene/terrain/mod.rs","lineNumber":143,"sourceCode":"\n/// A 2D-array interface to the height map data of a chunk.\n/// This interface is aware of the one-pixel margin around the edges\n/// of the height map data, so valid x-coordinates are in the range -1..=width\n/// and y-coordinates are in the range -1..=height.\n/// (0,0) is the actual origin of the chunk, while (-1,-1) is the in the margin of the chunk.\npub struct ChunkHeightData<'a>(pub ResourceDataRef<'a, Texture>);\n/// A mutable 2D-array interface to the height map data of a chunk.\n/// This interface is aware of the one-pixel margin around the edges\n/// of the height map data, so valid x-coordinates are in the range -1..=width.\n/// (0,0) is the actual origin of the chunk, while (-1,-1) is the in the margin of the chunk.\npub struct ChunkHeightMutData<'a>(pub TextureDataRefMut<'a>);\n\nimpl ChunkHeightData<'_> {\n    /// The size of the hight map, excluding the margins\n    pub fn size(&self) -> Vector2<u32> {\n        match self.0.kind() {\n            TextureKind::Rectangle { width, height } => Vector2::new(width - 2, height - 2),\n            _ => panic!(\"Invalid texture kind.\"),\n        }\n    }\n    /// The length of each horizontal row in the underlying texture.\n    pub fn row_size(&self) -> usize {\n        match self.0.kind() {\n            TextureKind::Rectangle { width, .. } => width as usize,\n            _ => panic!(\"Invalid texture kind.\"),\n        }\n    }\n    /// Get the value at the given position, if possible.\n    pub fn get(&self, position: Vector2<i32>) -> Option<f32> {\n        if self.is_valid_index(position) {\n            Some(self[position])\n        } else {\n            None\n        }\n    }\n    #[inline]","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/FyroxEngine/Fyrox/blob/76c91aad8eca488ce527b1af707be8b3b24ad72d/fyrox-impl/src/scene/terrain/mod.rs#L125-L161","documentation":"ChunkHeightData::size extracts the height map dimensions from the underlying terrain height texture, subtracting the margin pixels. It only supports `TextureKind::Rectangle` and panics with \"Invalid texture kind.\" for any other texture kind (e.g. 1D or 3D textures), since height maps must be 2D rectangles.","triggerScenarios":"A terrain's height map texture is not a `TextureKind::Rectangle` (e.g. assigned a 1D/3D texture, or a texture whose kind was changed after creation), then `size()` is invoked — directly or transitively via `is_valid_index` when reading height data with `index`/`get`.","commonSituations":"Programmatically building terrain and passing a wrongly-initialized texture; loading a scene where the height map resource failed to resolve to a 2D texture; terrain code in mods/plugins reading height data before the texture is properly set.","solutions":["Ensure the terrain height map is a 2D `TextureKind::Rectangle` texture (create/load it as such).","Check `texture.kind()` matches `TextureKind::Rectangle` before accessing chunk height data.","If the texture loads asynchronously, wait for its state to be Ok (e.g. `Texture::load` result ready) before querying terrain height."],"exampleFix":"// before\nlet hmap = terrain.height_map();\nlet size = ChunkHeightData(hmap).size();\n// after\nlet hmap = terrain.height_map();\nif matches!(hmap.kind(), TextureKind::Rectangle { .. }) {\n    let size = ChunkHeightData(hmap).size();\n}","handlingStrategy":"validation","validationCode":"if matches!(terrain.height_map().kind(), TextureKind::Rectangle { .. }) {\n    let size = ChunkHeightData(terrain.height_map()).size();\n}","typeGuard":"fn is_rectangle_texture(tex: &Texture) -> bool {\n    matches!(tex.kind(), TextureKind::Rectangle { .. })\n}","tryCatchPattern":"// Rust panic - avoid instead by checking texture.kind() == TextureKind::Rectangle before any ChunkHeightData access.","preventionTips":["Only ever assign 2D Rectangle textures as terrain height maps.","Check texture load state is Ok before reading terrain heights.","Validate height map kind when loading scenes or building terrain programmatically."],"tags":["panic","terrain","texture-kind","invalid-state"],"backgroundTag":"unsupported-operation","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"}