{"record":{"id":"708f157ae5914437","repo":"FyroxEngine/Fyrox","slug":"texture-is-not-rectangle","errorCode":null,"errorMessage":"Texture is not rectangle","messagePattern":"Texture is not rectangle","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"fyrox-impl/src/scene/terrain/mod.rs","lineNumber":477,"sourceCode":"            layer_masks: Default::default(),\n            height_map_modifications_count: 0,\n        }\n    }\n}\n\nimpl Chunk {\n    /// Return a view of the height data as a 2D array of f32.\n    pub fn height_data(&self) -> ChunkHeightData {\n        ChunkHeightData(self.heightmap.as_ref().map(|r| r.data_ref()).unwrap())\n    }\n\n    /// Modify the height texture of the chunk to give it a one pixel margin around all four edges.\n    /// The [`Chunk::height_map_size`] is increased to match. The margin is initialized to zero.\n    pub fn create_margin(&mut self) {\n        let data = self.heightmap.as_ref().map(|r| r.data_ref()).unwrap();\n        let size = match data.kind() {\n            TextureKind::Rectangle { width, height } => Vector2::new(width, height),\n            _ => panic!(\"Texture is not rectangle\"),\n        };\n        let data_f32 = From::<&[f32]>::from(data.data_of_type().unwrap());\n        let result = create_zero_margin(data_f32, size);\n        drop(data);\n        self.heightmap = Some(make_height_map_texture(result, size.map(|x| x + 2)));\n        self.height_map_size = self.height_map_size.map(|x| x + 2);\n    }\n    /// Check the heightmap for modifications and update data as necessary.\n    pub fn update(&self) {\n        let Some(heightmap) = self.heightmap.as_ref() else {\n            return;\n        };\n        let count = heightmap.data_ref().modifications_count();\n        let mut quad_tree = self.quad_tree.safe_lock();\n        if count != quad_tree.height_mod_count() {\n            *quad_tree = make_quad_tree(&self.heightmap, self.height_map_size, self.block_size);\n        }\n    }","sourceCodeStart":459,"sourceCodeEnd":495,"githubUrl":"https://github.com/FyroxEngine/Fyrox/blob/76c91aad8eca488ce527b1af707be8b3b24ad72d/fyrox-impl/src/scene/terrain/mod.rs#L459-L495","documentation":"Chunk::create_margin adds a 1px zero margin around the chunk's heightmap, but first requires the current heightmap texture to be TextureKind::Rectangle. If the texture has any other kind, it panics with \"Texture is not rectangle\". Like the other terrain panics, this guards the invariant that terrain heightmaps are 2D rectangle textures of f32 data.","triggerScenarios":"Calling chunk.create_margin() on a chunk whose heightmap texture is not a Rectangle-kind texture (wrong TextureKind variant or missing/unset kind). Note it also unwraps data_of_type::<f32>(), so non-f32 heightmaps will additionally fail.","commonSituations":"Assigning a custom-built or image-loaded texture as a chunk heightmap and then calling create_margin; terrain code migrated from versions with different heightmap representations; procedural generation that skips the terrain texture helpers.","solutions":["Ensure the heightmap texture kind is TextureKind::Rectangle (build it with make_height_map_texture) before calling create_margin.","Verify data.kind() matches TextureKind::Rectangle before calling create_margin and rebuild the heightmap otherwise.","Use the standard terrain construction path (TerrainBuilder / chunk height data editing) which already maintains correct texture kinds.","If margins are the goal, prefer building the heightmap with margin included up front instead of post-hoc create_margin on foreign textures."],"exampleFix":"// before\nchunk.set_height_map(my_non_rectangle_texture);\nchunk.create_margin(); // panics\n// after\nassert!(matches!(my_tex.data_ref().kind(), TextureKind::Rectangle { .. }));\nchunk.set_height_map(my_tex);\nchunk.create_margin();","handlingStrategy":"validation","validationCode":"let data = chunk.height_map().unwrap().data_ref();\nassert!(matches!(data.kind(), TextureKind::Rectangle { .. }));\nassert!(data.data_of_type::<f32>().is_some());\nchunk.create_margin();","typeGuard":"fn can_create_margin(tex: &TextureResource) -> bool {\n    let d = tex.data_ref();\n    matches!(d.kind(), TextureKind::Rectangle { .. }) && d.data_of_type::<f32>().is_some()\n}","tryCatchPattern":"// No recoverable catch for panics; validate first\nif can_create_margin(&chunk.height_map().unwrap()) {\n    chunk.create_margin();\n} else {\n    // regenerate the heightmap from source data\n}","preventionTips":["Ensure heightmaps come from the terrain API before mutating them with create_margin.","Validate texture kind and dtype before margin operations.","Prefer constructing heightmaps already including margins over post-hoc create_margin.","Test margin creation on every terrain-construction code path."],"tags":["panic","texture-kind","terrain","rust"],"backgroundTag":"invalid-enum-value","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"}