{"record":{"id":"aaec15ad7d1ac6cd","repo":"Unity-Technologies/UnityCsReference","slug":"must-be-0-1-or-2","errorCode":null,"errorMessage":"Must be 0, 1, or 2","messagePattern":"Must be 0, 1, or 2","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/Handles/BoundsHandle/PrimitiveBoundsHandle.cs","lineNumber":234,"sourceCode":"        }\n\n        protected bool IsAxisEnabled(Axes axis)\n        {\n            return (axes & axis) == axis;\n        }\n\n        protected bool IsAxisEnabled(int vector3Axis)\n        {\n            switch (vector3Axis)\n            {\n                case 0:\n                    return IsAxisEnabled(Axes.X);\n                case 1:\n                    return IsAxisEnabled(Axes.Y);\n                case 2:\n                    return IsAxisEnabled(Axes.Z);\n                default:\n                    throw new ArgumentOutOfRangeException(\"vector3Axis\", \"Must be 0, 1, or 2\");\n            }\n        }\n\n        private void MidpointHandles(ref Vector3 minPos, ref Vector3 maxPos, bool isCameraInsideBox)\n        {\n            Vector3 xAxis = Vector3.right;\n            Vector3 yAxis = Vector3.up;\n            Vector3 zAxis = Vector3.forward;\n            Vector3 middle = (maxPos + minPos) * 0.5f;\n\n            Vector3 localPos, newPos;\n            if (IsAxisEnabled(Axes.X))\n            {\n                // +X\n                localPos = new Vector3(maxPos.x, middle.y, middle.z);\n                newPos = MidpointHandle(m_ControlIDs[(int)HandleDirection.PositiveX], localPos, yAxis, zAxis, isCameraInsideBox);\n                maxPos.x = Mathf.Max(newPos.x, minPos.x);\n","sourceCodeStart":216,"sourceCodeEnd":252,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/Handles/BoundsHandle/PrimitiveBoundsHandle.cs#L216-L252","documentation":"IsAxisEnabled(int vector3Axis) maps integer indices 0 to X, 1 to Y, 2 to Z within the Axes enum flags. Any value outside 0-2 is invalid because Vector3 and the Axes enum only define three axes.","triggerScenarios":"Passing an axis index other than 0, 1, or 2, often from a loop that iterates beyond 2 or from a computed index that wraps or overflows.","commonSituations":"Custom PrimitiveBoundsHandle subclasses that override or extend axis logic using integer indices; a loop variable or bit-shift result that exceeds the valid range.","solutions":["Ensure the axis index is within 0-2 before calling; validate or clamp.","Prefer calling IsAxisEnabled(Axes) with the enum value directly instead of the integer overload."],"exampleFix":"// before\nfor (int i = 0; i <= 3; i++)\n    if (IsAxisEnabled(i)) { ... }\n// after\nforeach (Axes axis in new[] { Axes.X, Axes.Y, Axes.Z })\n    if (IsAxisEnabled(axis)) { ... }","handlingStrategy":"validation","validationCode":"if (vector3Axis < 0 || vector3Axis > 2)\n    throw new ArgumentOutOfRangeException(nameof(vector3Axis));\nbool enabled = IsAxisEnabled(vector3Axis);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Prefer the IsAxisEnabled(Axes) enum overload over the integer overload.","If using integer indices, ensure loops iterate exactly 0..2 and never exceed 2."],"tags":["bounds-handle","argument-validation","unity-editor"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}