{"record":{"id":"f989d910742baeb5","repo":"AvaloniaUI/Avalonia","slug":"maxdegree-must-be-between-1-and-3","errorCode":null,"errorMessage":"maxDegree must be between 1 and 3","messagePattern":"maxDegree must be between 1 and 3","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Media/PreciseEllipticArcHelper.cs","lineNumber":422,"sourceCode":"                _sinTheta = Math.Sin(theta);\n                _maxDegree = 3;\n                _defaultFlatness = 0.5; //half a pixel\n                ComputeFocii();\n                ComputeEndPoints();\n                ComputeBounds();\n                ComputeDerivedFlatnessParameters();\n            }\n\n            /// <summary>\n            /// Sets the maximal degree allowed for Bezier curve approximation.\n            /// </summary>\n            /// <param name=\"maxDegree\">Maximal allowed degree (must be between 1 and 3)</param>\n            /// <exception cref=\"ArgumentException\">Thrown if maxDegree is not between 1 and 3</exception>\n            public void SetMaxDegree(int maxDegree)\n            {\n                if (maxDegree < 1 || maxDegree > 3)\n                {\n                    throw new ArgumentException(@\"maxDegree must be between 1 and 3\", nameof(maxDegree));\n                }\n                _maxDegree = maxDegree;\n            }\n\n            /// <summary>\n            /// Sets the default flatness for Bezier curve approximation\n            /// </summary>\n            /// <param name=\"defaultFlatness\">default flatness (must be greater than 1e-10)</param>\n            /// <exception cref=\"ArgumentException\">Thrown if defaultFlatness is lower than 1e-10</exception>\n            public void SetDefaultFlatness(double defaultFlatness)\n            {\n                if (defaultFlatness < 1.0E-10)\n                {\n                    throw new ArgumentException(@\"defaultFlatness must be greater than 1.0e-10\", nameof(defaultFlatness));\n                }\n                _defaultFlatness = defaultFlatness;\n            }\n","sourceCodeStart":404,"sourceCodeEnd":440,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Media/PreciseEllipticArcHelper.cs#L404-L440","documentation":"Thrown by SetMaxDegree on the precise elliptic-arc helper when maxDegree is outside the inclusive range 1..3. The Bezier approximation code only supports degrees 1 (linear), 2 (quadratic), and 3 (cubic); any other value has no implementation path.","triggerScenarios":"arc.SetMaxDegree(0), arc.SetMaxDegree(4), or arc.SetMaxDegree(-1).","commonSituations":"Configuring arc flattening quality from a UI slider or config value that allows out-of-range integers; defaulting an uninitialized int (0) into SetMaxDegree.","solutions":["Pass 1, 2, or 3 (3 is the typical default for cubic approximation quality).","Clamp the input: var d = Math.Clamp(userValue, 1, 3); arc.SetMaxDegree(d);","Validate the source configuration range (slider min=1, max=3)."],"exampleFix":"// before\narc.SetMaxDegree(userQuality); // userQuality could be 0 or 5\n\n// after\narc.SetMaxDegree(Math.Clamp(userQuality, 1, 3));","handlingStrategy":"validation","validationCode":"var d = Math.Clamp(maxDegree, 1, 3);\narc.SetMaxDegree(d);","typeGuard":"static bool IsValidDegree(int d) => d is >= 1 and <= 3;","tryCatchPattern":null,"preventionTips":["Bound UI/config inputs for degree to [1,3].","Initialize the degree variable explicitly; never rely on default(int) (0)."],"tags":["avalonia","arc","bezier","argument","configuration"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}