{"record":{"id":"d2d7504726d9d521","repo":"stride3d/stride","slug":"l-parameter-should-be-between-0-and-0-order-1","errorCode":null,"errorMessage":"'l' parameter should be between '0' and '{0}' (order-1).","messagePattern":"'l' parameter should be between '0' and '(.+?)' \\(order-1\\)\\.","errorType":"exception","errorClass":"IndexOutOfRangeException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Mathematics/SphericalHarmonics.cs","lineNumber":98,"sourceCode":"    {\n        get\n        {\n            CheckIndicesValidity(l, m, order);\n            return Coefficients[LmToCoefficientIndex(l, m)];\n        }\n        set\n        {\n            CheckIndicesValidity(l, m, order);\n            Coefficients[LmToCoefficientIndex(l, m)] = value;\n        }\n    }\n\n    // ReSharper disable UnusedParameter.Local\n    private static void CheckIndicesValidity(int l, int m, int maxOrder)\n    // ReSharper restore UnusedParameter.Local\n    {\n        if (l > maxOrder - 1)\n            throw new IndexOutOfRangeException(\"'l' parameter should be between '0' and '{0}' (order-1).\".ToFormat(maxOrder - 1));\n\n        if (Math.Abs(m) > l)\n            throw new IndexOutOfRangeException(\"'m' parameter should be between '-l' and '+l'.\");\n    }\n\n    private static int LmToCoefficientIndex(int l, int m)\n    {\n        return l * l + l + m;\n    }\n}\n\n/// <summary>\n/// A spherical harmonics representation of a cubemap.\n/// </summary>\n[DataContract(\"SphericalHarmonics\")]\npublic class SphericalHarmonics : SphericalHarmonics<Color3>\n{\n    private readonly float[] baseValues;","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Mathematics/SphericalHarmonics.cs#L80-L116","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nfor (int l = 0; l <= order; l++) EvaluateL(l, m);\n// after\nfor (int l = 0; l < order; l++) EvaluateL(l, m);","handlingStrategy":"validation","validationCode":"if (l >= 0 && l <= order - 1 && Math.Abs(m) <= l) { EvaluateBasis(l, m); }","typeGuard":"bool IsValidShIndices(int l, int m, int order) => l >= 0 && l <= order - 1 && Math.Abs(m) <= l;","tryCatchPattern":"try { EvaluateBasis(l, m); }\ncatch (IndexOutOfRangeException ex) { /* validate l/m against order and skip or clamp */ }","preventionTips":["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"],"tags":["mathematics","spherical-harmonics","index-out-of-range"],"backgroundTag":"index-out-of-range","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}