FyroxEngine/Fyrox · error

Invalid Terrain quad tree node size

Error message

Invalid Terrain quad tree node size

What it means

Terrain quad-tree node aabb computation validates that the node's size is at least 1 on each axis; if not, it logs this error and returns a default (empty) AABB. A zero/negative node size means the quad tree was built with invalid parameters and spatial queries would be meaningless.

Solutions

  1. Fix terrain construction parameters so height_map_size >= 3x3 and physical_size components are positive before building the quad tree.
  2. Reload or re-save the terrain resource if its stored quad-tree data is corrupted.
  3. Guard debug_draw/select calls so they only run on terrains with valid, fully initialized quad trees.

Example fix

// before
let terrain = TerrainBuilder::new()
    .with_height_map_size(Vector2::new(1, 1)) // invalid
    .build(...);

// after
let terrain = TerrainBuilder::new()
    .with_height_map_size(Vector2::new(64, 64))
    .build(...);
Defensive patterns

Strategy: validation

Validate before calling

// Validate terrain parameters before building the quad tree:
assert!(height_map_size.x >= 3 && height_map_size.y >= 3, "height map too small");
assert!(physical_size.x > 0.0 && physical_size.y > 0.0, "physical size must be positive");

Type guard

fn valid_terrain_params(hm: Vector2<u32>, phys: Vector2<f32>) -> bool {
    hm.x >= 3 && hm.y >= 3 && phys.x > 0.0 && phys.y > 0.0
}

Prevention

When it happens

Trigger: Calling aabb (directly or via debug_draw/select) on a TerrainQuadTreeNode whose size.x or size.y < 1 — resulting from building the quad tree with invalid heightmap/physical size parameters.

Common situations: Terrain created with a heightmap smaller than valid bounds or zero physical size; corrupted saved terrain data; calling selection/debug drawing on a not-yet-built or degenerate quad tree.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


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

Appendix: source

Thrown at fyrox-impl/src/scene/terrain/quadtree.rs:235

            min_height,
            max_height,
        }
    }

    /// Construct an AABB for the node.
    /// * transform: Transformation matrix to apply to the AABB just before it is returned.
    /// * height_map_size: The overall size of the whole of the height map data that this node is a part of.
    /// * physical_size: The size of the whole of the height map data in world units.
    /// Note that the sizes of these arguments are only for the chunk of this [QuadTree].
    /// Other chunks are not included since they have entirely separate height data.
    pub fn aabb(
        &self,
        transform: &Matrix4<f32>,
        height_map_size: Vector2<u32>,
        physical_size: Vector2<f32>,
    ) -> AxisAlignedBoundingBox {
        if self.size.x < 1 || self.size.y < 1 {
            Log::err("Invalid Terrain quad tree node size");
            return Default::default();
        }
        if height_map_size.x < 3 || height_map_size.y < 3 {
            Log::err("Invalid Terrain height texture size");
            return Default::default();
        }
        if self.position.x < 1 || self.position.y < 1 {
            Log::err("Invalid Terrain quad tree node position");
            return Default::default();
        }
        // Convert sizes from pixel sizes to mesh sizes.
        // For calculating AABB, we do not care about the number of vertices;
        // we care about the number of edges between vertices, which is one fewer.
        let real_map_size = height_map_size.map(|x| x - 3);
        // Nodes have no margins, but we still need to subtract one so we are measuring length, not counting vertices.
        let real_node_size = self.size.map(|x| x - 1);
        // Exclude the one-pixel margin when calculating the real position of this node.
        let pos = self.position.map(|x| x - 1);

View on GitHub (pinned to 76c91aad8e)