FyroxEngine/Fyrox · error
Command swap failed due to texture size mismatch
Error message
Command swap failed due to texture size mismatch
What it means
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.
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.
Defensive patterns
Strategy: validation
Validate before calling
// Finish or clear strokes before resizing terrain textures:
if stroke.in_progress() {
stroke.finish_stroke();
}
terrain.set_layer_texture_size(new_size); Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: Tensor shape mismatch errors ("must have shape", "expected shape ... got ..."): when tensor dimensions disagree with what an op or layer was told to expect — this error's family across 6 libraries.
Related errors
- Invalid pixel position
- Height data type error
- Missing hole mask texture
- Terrain brush operation dropped due to sanity limit
- Invalid brush stroke. Holes are not enabled on terrain.
AI-assisted analysis of FyroxEngine/Fyrox@76c91aad8e (2026-09-10).
Data as JSON: /api/errors/35570c0c396a16f2.
Report an issue: GitHub.
Appendix: source
Thrown at fyrox-impl/src/scene/terrain/brushstroke/mod.rs:967
}
}
fn size_from_texture(texture: &ResourceDataRef<'_, Texture>) -> Vector2<u32> {
match texture.kind() {
crate::resource::texture::TextureKind::Rectangle { width, height } => {
Vector2::new(width, height)
}
_ => unreachable!("Terrain texture was not rectangle."),
}
}
impl ChunkData {
/// Extract the size from the given texture and return true if that size matches
/// the size required by this data. Log an error message and return false otherwise.
fn verify_texture_size(&self, texture: &ResourceDataRef<'_, Texture>) -> bool {
let size = size_from_texture(texture);
if size != self.size {
Log::err("Command swap failed due to texture size mismatch");
false
} else {
true
}
}
/// Create a ChunkData for the given texture at the given position.
pub fn from_texture(grid_position: Vector2<i32>, texture: &TextureResource) -> Self {
let data_ref = texture.data_ref();
let size = size_from_texture(&data_ref);
let data = Box::<[u8]>::from(data_ref.data());
Self {
grid_position,
size,
content: data,
}
}
/// Swap the content of this data with the content of the given chunk's height map.
pub fn swap_height(&mut self, chunk: &mut Chunk) {View on GitHub (pinned to 76c91aad8e)