stride3d/stride · error · IndexOutOfRangeException
'l' parameter should be between '0' and
Error message
'l' parameter should be between '0' and '{0}' (order-1). What it means
CheckIndicesValidity validates SH basis-function indices: l must be at most order-1 (and m within ±l). Passing l > maxOrder-1 throws IndexOutOfRangeException with a message that (despite the {0} placeholder intent) is formatted with the max valid l. It guards coefficient-array bounds for (l, m) index math.
Solutions
- Ensure l ranges from 0 to Order-1 when evaluating basis functions
- Fix loop bounds to l < order (not l <= order)
- Clamp l to order-1 before computing the coefficient index
Example fix
// before for (int l = 0; l <= order; l++) EvaluateL(l, m); // after for (int l = 0; l < order; l++) EvaluateL(l, m);
Defensive patterns
Strategy: validation
Validate before calling
if (l >= 0 && l <= order - 1 && Math.Abs(m) <= l) { EvaluateBasis(l, m); } Type guard
bool IsValidShIndices(int l, int m, int order) => l >= 0 && l <= order - 1 && Math.Abs(m) <= l;
Try / catch
try { EvaluateBasis(l, m); }
catch (IndexOutOfRangeException ex) { /* validate l/m against order and skip or clamp */ } Prevention
- Bound SH loops by l < order and |m| <= l
- Never mix coefficient sets of different orders without clamping
- Reuse a shared index-validation helper for all SH math
When it happens
Trigger: Calling Evaluate/EvaluateDirection-related internal paths (via SphericalHarmonics members) with l greater than order-1, e.g. iterating l up to order instead of order-1, or using a band index from a different-order dataset.
Common situations: SH evaluation loops with off-by-one band bounds; mixing coefficients from SH datasets of different orders; direct computation of basis functions for an unsupported band.
Related errors
- Indices for Double3 run from 0 to 2, inclusive.
- Indices for Double4 run from 0 to 3, inclusive.
- Indices for Plane run from 0 to 3, inclusive.
- Indices for Quaternion run from 0 to 3, inclusive.
- Only orders inferior or equal to 5 are supported
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/d2d7504726d9d521.
Report an issue: GitHub.
Appendix: source
Thrown at sources/core/Stride.Core.Mathematics/SphericalHarmonics.cs:98
{
get
{
CheckIndicesValidity(l, m, order);
return Coefficients[LmToCoefficientIndex(l, m)];
}
set
{
CheckIndicesValidity(l, m, order);
Coefficients[LmToCoefficientIndex(l, m)] = value;
}
}
// ReSharper disable UnusedParameter.Local
private static void CheckIndicesValidity(int l, int m, int maxOrder)
// ReSharper restore UnusedParameter.Local
{
if (l > maxOrder - 1)
throw new IndexOutOfRangeException("'l' parameter should be between '0' and '{0}' (order-1).".ToFormat(maxOrder - 1));
if (Math.Abs(m) > l)
throw new IndexOutOfRangeException("'m' parameter should be between '-l' and '+l'.");
}
private static int LmToCoefficientIndex(int l, int m)
{
return l * l + l + m;
}
}
/// <summary>
/// A spherical harmonics representation of a cubemap.
/// </summary>
[DataContract("SphericalHarmonics")]
public class SphericalHarmonics : SphericalHarmonics<Color3>
{
private readonly float[] baseValues;View on GitHub (pinned to 96fad776d2)