{"record":{"id":"d406949bb28225bd","repo":"stride3d/stride","slug":"indices-for-int4-run-from-0-to-3-inclusive","errorCode":null,"errorMessage":"Indices for Int4 run from 0 to 3, inclusive.","messagePattern":"Indices for Int4 run from 0 to 3, inclusive\\.","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Mathematics/Int4.cs","lineNumber":156,"sourceCode":"        W = values[3];\n    }\n\n    /// <summary>\n    ///   Gets or sets the component at the specified index.\n    /// </summary>\n    /// <value>The value of the X, Y, Z, or W component, depending on the index.</value>\n    /// <param name = \"index\">The index of the component to access. Use 0 for the X component, 1 for the Y component, 2 for the Z component, and 3 for the W component.</param>\n    /// <returns>The value of the component at the specified index.</returns>\n    /// <exception cref = \"ArgumentOutOfRangeException\">Thrown when the <paramref name = \"index\" /> is out of the range [0, 3].</exception>\n    public int this[int index]\n    {\n        readonly get => index switch\n        {\n            0 => X,\n            1 => Y,\n            2 => Z,\n            3 => W,\n            _ => throw new ArgumentOutOfRangeException(nameof(index), \"Indices for Int4 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":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Mathematics/Int4.cs#L138-L174","documentation":"The Int4 indexer bounds-checks the index parameter and throws ArgumentOutOfRangeException when the index is outside [0, 3]. It is a generic guard on component access: 0 selects X, 1 Y, 2 Z, 3 W; any negative or >= 4 index is rejected.","triggerScenarios":"Reading v[index] with index outside 0..3, e.g. loops bounded by a larger count, negative indices, or indices computed from quaternion/color metadata with more components.","commonSituations":"Generic component iteration over mixed vector types; reflection-driven property access with bad ordinal mapping.","solutions":["Bound loops to i < 4 for Int4","Validate: if ((uint)index < 4) before access","For type-generic code, map the component count per vector type"],"exampleFix":"// before\nfor (int i = 0; i < 5; i++) sum += v[i]; // throws at i=4\n// after\nfor (int i = 0; i < 4; i++) sum += v[i];","handlingStrategy":"validation","validationCode":"if (index is < 0 or > 3)\n    throw new ArgumentOutOfRangeException(nameof(index));\nvar component = v[index];","typeGuard":"static bool IsValidInt4Index(int i) => (uint)i < 4;","tryCatchPattern":"try { component = v[index]; }\ncatch (ArgumentOutOfRangeException ex) when (ex.ParamName == \"index\")\n{\n    component = 0; // or surface a data error\n}","preventionTips":["Bound loops to 4 for Int4","Don't reuse Int2/Int3 loop bounds on Int4","Use X/Y/Z/W properties for statically known components"],"tags":["csharp","stride","mathematics","indexer","argument-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"}