stride3d/stride · error · ArgumentException

Array cannot be empty or null.

Error message

Array cannot be empty or null.

What it means

BoundingSphere.FromPoints(Vector3[]) computes the minimal bounding sphere from an array of points and requires at least one point. Null is rejected with ArgumentNullException and an empty array with this ArgumentException, since no sphere can be derived from zero points.

Solutions

  1. Check points != null && points.Length > 0 before calling; pick a defined fallback for the empty case.
  2. Skip sphere computation entirely when there are no points.
  3. Fix the upstream data source that produces the empty point list.
  4. If degenerate input is possible, wrap in try-catch ArgumentException and substitute a default sphere.

Example fix

// before
BoundingSphere.FromPoints(points, out var sphere); // throws when points is empty
// after
var sphere = points.Length > 0
    ? BoundingSphere.FromPoints(points)
    : new BoundingSphere(Vector3.Zero, 0f);
Defensive patterns

Strategy: validation

Validate before calling

if (points is not { Length: > 0 })
    throw new ArgumentException("points must contain at least one vertex.", nameof(points));

Type guard

bool HasPoints(Vector3[]? p) => p is { Length: > 0 };

Try / catch

try { BoundingSphere.FromPoints(points, out var s); }
catch (ArgumentException) { var s = new BoundingSphere(Vector3.Zero, 0f); }

Prevention

When it happens

Trigger: Calling BoundingSphere.FromPoints with an empty array (points.Length == 0), typically from data sources that produced no vertices, filtered-out points, or an uninitialized buffer.

Common situations: Mesh loading where a submesh has zero vertices; point clouds after aggressive culling; deserialized geometry lists that are empty by default.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/b21d0c0d27b3a519. Report an issue: GitHub.

Appendix: source

Thrown at sources/core/Stride.Core.Mathematics/BoundingSphere.cs:194

    /// <summary>
    /// Determines whether the current objects contains a <see cref="BoundingSphere"/>.
    /// </summary>
    /// <param name="sphere">The sphere to test.</param>
    /// <returns>The type of containment the two objects have.</returns>
    public ContainmentType Contains(ref readonly BoundingSphere sphere)
    {
        return CollisionHelper.SphereContainsSphere(ref this, in sphere);
    }

    /// <summary>
    /// Constructs a <see cref="BoundingSphere"/> that fully contains the given points.
    /// </summary>
    /// <param name="points">The points that will be contained by the sphere.</param>
    /// <param name="result">When the method completes, contains the newly constructed bounding sphere.</param>
    public static unsafe void FromPoints(Vector3[] points, out BoundingSphere result)
    {
        ArgumentNullException.ThrowIfNull(points);
        if (points.Length == 0) throw new ArgumentException("Array cannot be empty or null.", nameof(points));
        fixed (void* pointsPtr = points)
        {
            FromPoints((IntPtr)pointsPtr, 0, points.Length, Unsafe.SizeOf<Vector3>(), out result);
        }
    }

    /// <summary>
    /// Constructs a <see cref="Stride.Core.Mathematics.BoundingSphere" /> that fully contains the given unmanaged points.
    /// </summary>
    /// <param name="vertexBufferPtr">A pointer to of vertices containing points.</param>
    /// <param name="vertexPositionOffsetInBytes">The point offset in bytes starting from the vertex structure.</param>
    /// <param name="vertexCount">The verterx vertexCount.</param>
    /// <param name="vertexStride">The vertex stride (size of vertex).</param>
    /// <param name="result">When the method completes, contains the newly constructed bounding sphere.</param>
    public static unsafe void FromPoints(IntPtr vertexBufferPtr, int vertexPositionOffsetInBytes, int vertexCount, int vertexStride, out BoundingSphere result)
    {
        if (vertexBufferPtr == IntPtr.Zero)
        {

View on GitHub (pinned to 96fad776d2)