{"record":{"id":"0613eb133c661701","repo":"stride3d/stride","slug":"indices-for-uint4-run-from-0-to-3-inclusive","errorCode":null,"errorMessage":"Indices for UInt4 run from 0 to 3, inclusive.","messagePattern":"Indices for UInt4 run from 0 to 3, inclusive\\.","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Mathematics/UInt4.cs","lineNumber":161,"sourceCode":"    /// <returns>The value of the component at the specified index.</returns>\n    /// <exception cref = \"System.ArgumentOutOfRangeException\">Thrown when the <paramref name = \"index\" /> is out of the range [0, 3].</exception>\n    public uint this[uint index]\n    {\n        get\n        {\n            switch (index)\n            {\n                case 0:\n                    return X;\n                case 1:\n                    return Y;\n                case 2:\n                    return Z;\n                case 3:\n                    return W;\n            }\n\n            throw new ArgumentOutOfRangeException(nameof(index), \"Indices for UInt4 run from 0 to 3, inclusive.\");\n        }\n\n        set\n        {\n            switch (index)\n            {\n                case 0:\n                    X = value;\n                    break;\n                case 1:\n                    Y = value;\n                    break;\n                case 2:\n                    Z = value;\n                    break;\n                case 3:\n                    W = value;\n                    break;","sourceCodeStart":143,"sourceCodeEnd":179,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Mathematics/UInt4.cs#L143-L179","documentation":"Indexer bounds guard on UInt4 this[index]: the requested component index is outside [0,3]; none of the switch cases matched, so there is no X/Y/Z/W component to return. The faulting input is the index argument to the indexer.","triggerScenarios":"Reading v[i] on a UInt4 with i outside 0..3, e.g. looping to i < 5 for a 4-component type, or using a negative index computed from an off-by-one expression.","commonSituations":"Generic component-copy loops sized from a different vector type; iterating both a Vector4-sized buffer and UInt4 values with a shared loop bound; computed index from bad data.","solutions":["Clamp or validate the index to 0..3 before indexing.","Fix loop bounds to i < 4 when iterating UInt4 components.","Use component properties (X, Y, Z, W) directly when the index is known statically."],"exampleFix":"// before\nfor (int i = 0; i < 5; i++) sum += v[i];\n// after\nfor (int i = 0; i < 4; i++) sum += v[i];","handlingStrategy":"validation","validationCode":"if (index < 0 || index > 3)\n    throw new ArgumentOutOfRangeException(nameof(index), \"UInt4 index must be 0..3.\");\nvar component = v[index];","typeGuard":"bool IsValidUInt4Index(int i) => i >= 0 && i <= 3;","tryCatchPattern":"try\n{\n    component = v[index];\n}\ncatch (ArgumentOutOfRangeException)\n{\n    component = 0; // or rethrow with context about the bad index\n}","preventionTips":["Use compile-time constants or named properties (X/Y/Z/W) instead of runtime indices.","Bound component loops with the vector's component count (4 for UInt4).","Never reuse loop bounds from other vector types when indexing."],"tags":["mathematics","index-out-of-range","indexer"],"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"}