FyroxEngine/Fyrox · error

Invalid texture kind.

Error message

Invalid texture kind.

What it means

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.

Solutions

  1. Ensure the terrain height map is a 2D `TextureKind::Rectangle` texture (create/load it as such).
  2. Check `texture.kind()` matches `TextureKind::Rectangle` before accessing chunk height data.
  3. If the texture loads asynchronously, wait for its state to be Ok (e.g. `Texture::load` result ready) before querying terrain height.

Example fix

// before
let hmap = terrain.height_map();
let size = ChunkHeightData(hmap).size();
// after
let hmap = terrain.height_map();
if matches!(hmap.kind(), TextureKind::Rectangle { .. }) {
    let size = ChunkHeightData(hmap).size();
}
Defensive patterns

Strategy: validation

Validate before calling

if matches!(terrain.height_map().kind(), TextureKind::Rectangle { .. }) {
    let size = ChunkHeightData(terrain.height_map()).size();
}

Type guard

fn is_rectangle_texture(tex: &Texture) -> bool {
    matches!(tex.kind(), TextureKind::Rectangle { .. })
}

Try / catch

// Rust panic - avoid instead by checking texture.kind() == TextureKind::Rectangle before any ChunkHeightData access.

Prevention

When it happens

Trigger: 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`.

Common situations: 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.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of FyroxEngine/Fyrox@76c91aad8e (2026-09-10). Data as JSON: /api/errors/fcfc9566342e503a. Report an issue: GitHub.

Appendix: source

Thrown at fyrox-impl/src/scene/terrain/mod.rs:143

/// A 2D-array interface to the height map data of a chunk.
/// This interface is aware of the one-pixel margin around the edges
/// of the height map data, so valid x-coordinates are in the range -1..=width
/// and y-coordinates are in the range -1..=height.
/// (0,0) is the actual origin of the chunk, while (-1,-1) is the in the margin of the chunk.
pub struct ChunkHeightData<'a>(pub ResourceDataRef<'a, Texture>);
/// A mutable 2D-array interface to the height map data of a chunk.
/// This interface is aware of the one-pixel margin around the edges
/// of the height map data, so valid x-coordinates are in the range -1..=width.
/// (0,0) is the actual origin of the chunk, while (-1,-1) is the in the margin of the chunk.
pub struct ChunkHeightMutData<'a>(pub TextureDataRefMut<'a>);

impl ChunkHeightData<'_> {
    /// The size of the hight map, excluding the margins
    pub fn size(&self) -> Vector2<u32> {
        match self.0.kind() {
            TextureKind::Rectangle { width, height } => Vector2::new(width - 2, height - 2),
            _ => panic!("Invalid texture kind."),
        }
    }
    /// The length of each horizontal row in the underlying texture.
    pub fn row_size(&self) -> usize {
        match self.0.kind() {
            TextureKind::Rectangle { width, .. } => width as usize,
            _ => panic!("Invalid texture kind."),
        }
    }
    /// Get the value at the given position, if possible.
    pub fn get(&self, position: Vector2<i32>) -> Option<f32> {
        if self.is_valid_index(position) {
            Some(self[position])
        } else {
            None
        }
    }
    #[inline]

View on GitHub (pinned to 76c91aad8e)