stride3d/stride · error · NotSupportedException

Only orders inferior or equal to 5 are supported

Error message

Only orders inferior or equal to 5 are supported

What it means

SphericalHarmonics.Order rejects any value greater than 5 with NotSupportedException, because the implementation only stores coefficients for orders up to 5. Higher-order harmonics are simply not supported by this type, so the setter fails fast instead of truncating silently.

Solutions

  1. Use an order of 5 or less
  2. Split higher-order data and truncate to order 5, accepting the precision loss
  3. Implement a custom SH type if higher orders are truly required

Example fix

// before
var sh = new SphericalHarmonics<Vector3>(8);
// after
var sh = new SphericalHarmonics<Vector3>(Math.Min(5, requestedOrder));
Defensive patterns

Strategy: validation

Validate before calling

if (order >= 1 && order <= 5) { var sh = new SphericalHarmonics<Vector3>(order); }

Type guard

bool IsSupportedShOrder(int o) => o >= 1 && o <= 5;

Try / catch

try { sh.Order = order; }
catch (NotSupportedException ex) { /* fall back to order 5 */ }

Prevention

When it happens

Trigger: Setting harmonics.Order = 6 or higher, e.g. to match an external lighting solver or a paper's band count; also constructing SphericalHarmonics<T> with order > 5 which flows into the Order setter.

Common situations: Porting SH code from libraries supporting higher orders; using precomputed radiance transfer data with more bands; misreading order vs. band count (order L has (L+1)^2 coefficients).

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 stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/e474f35e976eebe7. Report an issue: GitHub.

Appendix: source

Thrown at sources/core/Stride.Core.Mathematics/SphericalHarmonics.cs:37

{
    /// <summary>
    /// The maximum order supported.
    /// </summary>
    public const int MaximumOrder = 5;

    private int order;

    /// <summary>
    /// The order of calculation of the spherical harmonic.
    /// </summary>
    [DataMember(0)]
    public int Order
    {
        get { return order; }
        internal set
        {
            if (order > 5)
                throw new NotSupportedException("Only orders inferior or equal to 5 are supported");

            order = Math.Max(1, value);
        }
    }

    /// <summary>
    /// Get the coefficients defining the spherical harmonics (the spherical coordinates x{l,m} multiplying the spherical base Y{l,m}).
    /// </summary>
    [DataMember(1)]
    public TDataType[] Coefficients { get; internal set; }

    /// <summary>
    /// Initializes a new instance of the <see cref="SphericalHarmonics{TDataType}"/> class (null, for serialization).
    /// </summary>
    internal SphericalHarmonics()
    {
    }

View on GitHub (pinned to 96fad776d2)