bevyengine/bevy · error

point cloud must contain at least one point for Aabb2d const

Error message

point cloud must contain at least one point for Aabb2d construction

What it means

Aabb2d::from_point_cloud panics via .expect when the point slice is empty (crates/bevy_math/src/bounding/bounded2d/mod.rs:83) — the min/max fold needs a first point to seed from. This is a panic, not a Result: callers must filter empty inputs before invoking it.

Source

Thrown at crates/bevy_math/src/bounding/bounded2d/mod.rs:83

        }
    }

    /// Computes the smallest [`Aabb2d`] containing the given set of points,
    /// transformed by the rotation and translation of the given isometry.
    ///
    /// # Panics
    ///
    /// Panics if the given set of points is empty.
    #[inline]
    pub fn from_point_cloud(isometry: impl Into<Isometry2d>, points: &[Vec2]) -> Aabb2d {
        let isometry = isometry.into();

        // Transform all points by rotation
        let mut iter = points.iter().map(|point| isometry.rotation * *point);

        let first = iter
            .next()
            .expect("point cloud must contain at least one point for Aabb2d construction");

        let (min, max) = iter.fold((first, first), |(prev_min, prev_max), point| {
            (point.min(prev_min), point.max(prev_max))
        });

        Aabb2d {
            min: min + isometry.translation,
            max: max + isometry.translation,
        }
    }

    /// Computes the smallest [`BoundingCircle`] containing this [`Aabb2d`].
    #[inline]
    pub fn bounding_circle(&self) -> BoundingCircle {
        let radius = self.min.distance(self.max) / 2.0;
        BoundingCircle::new(self.center(), radius)
    }

View on GitHub (pinned to 396ca72708)

Solutions

  1. Check points is non-empty before calling from_point_cloud.
  2. Skip or early-return for empty point sets instead of computing bounds.
  3. Log where point clouds are produced to find the component emitting empty sets.

Example fix

// before
let aabb = Aabb2d::from_point_cloud(iso, &points); // panics on empty slice

// after
if points.is_empty() {
    return; // nothing to bound
}
let aabb = Aabb2d::from_point_cloud(iso, &points);
Defensive patterns

Strategy: validation

Validate before calling

fn point_cloud_aabb2d(iso: impl Into<Isometry2d>, points: &[Vec2]) -> Option<Aabb2d> {
    if points.is_empty() {
        return None;
    }
    Some(Aabb2d::from_point_cloud(iso, points))
}

Prevention

When it happens

Trigger: Calling Aabb2d::from_point_cloud(isometry, &[]) — an empty vertex set, empty collider points, or a collection sampled before any data arrived.

Common situations: Computing bounds for empty meshes during loading; physics colliders built from filtered geometry that matched nothing; procedural generation edge cases with zero points.

Related errors


AI-assisted analysis of bevyengine/bevy@396ca72708 (2026-08-20). Data as JSON: /api/errors/309bdaa05cbc493b. Report an issue: GitHub.