{"record":{"id":"35570c0c396a16f2","repo":"FyroxEngine/Fyrox","slug":"command-swap-failed-due-to-texture-size-mismatch","errorCode":null,"errorMessage":"Command swap failed due to texture size mismatch","messagePattern":"Command swap failed due to texture size mismatch","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"fyrox-impl/src/scene/terrain/brushstroke/mod.rs","lineNumber":967,"sourceCode":"    }\n}\n\nfn size_from_texture(texture: &ResourceDataRef<'_, Texture>) -> Vector2<u32> {\n    match texture.kind() {\n        crate::resource::texture::TextureKind::Rectangle { width, height } => {\n            Vector2::new(width, height)\n        }\n        _ => unreachable!(\"Terrain texture was not rectangle.\"),\n    }\n}\n\nimpl ChunkData {\n    /// Extract the size from the given texture and return true if that size matches\n    /// the size required by this data. Log an error message and return false otherwise.\n    fn verify_texture_size(&self, texture: &ResourceDataRef<'_, Texture>) -> bool {\n        let size = size_from_texture(texture);\n        if size != self.size {\n            Log::err(\"Command swap failed due to texture size mismatch\");\n            false\n        } else {\n            true\n        }\n    }\n    /// Create a ChunkData for the given texture at the given position.\n    pub fn from_texture(grid_position: Vector2<i32>, texture: &TextureResource) -> Self {\n        let data_ref = texture.data_ref();\n        let size = size_from_texture(&data_ref);\n        let data = Box::<[u8]>::from(data_ref.data());\n        Self {\n            grid_position,\n            size,\n            content: data,\n        }\n    }\n    /// Swap the content of this data with the content of the given chunk's height map.\n    pub fn swap_height(&mut self, chunk: &mut Chunk) {","sourceCodeStart":949,"sourceCodeEnd":985,"githubUrl":"https://github.com/FyroxEngine/Fyrox/blob/76c91aad8eca488ce527b1af707be8b3b24ad72d/fyrox-impl/src/scene/terrain/brushstroke/mod.rs#L949-L985","documentation":"ChunkData::verify_texture_size compares the actual size of the terrain texture being swapped with the size recorded when the brush command was created. On mismatch it logs this error and returns false, refusing the command swap, because pasting pixel data of wrong dimensions would corrupt the terrain chunk.","triggerScenarios":"Applying a queued brush command to a chunk texture whose dimensions changed since the command was captured — e.g. terrain texture resolution changed between stroke start and apply, or the command targets the wrong chunk's texture.","commonSituations":"Changing terrain texture size (chunk/layer resolution) mid-stroke; undo/redo of commands captured before a resolution change; strokes spanning terrains with differently sized layers.","solutions":["Avoid changing terrain texture/chunk resolution while a brush stroke is active; finish the stroke first.","Clear/reset the brush stroke after any terrain resize so stale ChunkData is discarded.","Ensure commands from one terrain aren't applied to another terrain with different layer texture sizes."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Finish or clear strokes before resizing terrain textures:\nif stroke.in_progress() {\n    stroke.finish_stroke();\n}\nterrain.set_layer_texture_size(new_size);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never change terrain chunk/layer texture resolution mid-stroke.","Reset brush state after any terrain resize or layer reconfiguration.","Don't share brush commands across terrains with different texture sizes."],"tags":["terrain","brush","texture","size-mismatch"],"backgroundTag":"tensor-shape-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"}