AvaloniaUI/Avalonia · error · ArgumentException
degree should be between {1} and {_maxDegree}
Error message
degree should be between {1} and {_maxDegree} What it means
Thrown by EstimateError when the requested Bezier degree is less than 1 or greater than the helper's current _maxDegree (set via SetMaxDegree, default 3). The error-estimation branches only handle degrees 1, 2, and 3 up to the configured maximum, so out-of-range degrees have no formula. The message interpolates the actual allowed upper bound, so it reads e.g. 'degree should be between 1 and 3'.
Source
Thrown at src/Avalonia.Base/Media/PreciseEllipticArcHelper.cs:566
/// <param name="x">Abscissa for which the value should be computed</param>
/// <param name="c">Coefficients array of the rational function</param>
/// <returns></returns>
private static double RationalFunction(double x, double[] c)
{
return (x * (x * c[0] + c[1]) + c[2]) / (x + c[3]);
}
/// <summary>
/// Estimate the approximation error for a sub-arc of the instance
/// </summary>
/// <param name="degree">Degree of the Bezier curve to use (1, 2 or 3)</param>
/// <param name="etaA">Start angle of the sub-arc</param>
/// <param name="etaB">End angle of the sub-arc</param>
/// <returns>Upper bound of the approximation error between the Bezier curve and the real ellipse</returns>
public double EstimateError(int degree, double etaA, double etaB)
{
if (degree < 1 || degree > _maxDegree)
throw new ArgumentException($"degree should be between {1} and {_maxDegree}", nameof(degree));
double eta = 0.5 * (etaA + etaB);
if (degree < 2)
{
//start point
double aCosEtaA = A * Math.Cos(etaA);
double bSinEtaA = B * Math.Sin(etaA);
double xA = Cx + aCosEtaA * _cosTheta - bSinEtaA * _sinTheta;
double yA = Cy + aCosEtaA * _sinTheta + bSinEtaA * _cosTheta;
//end point
double aCosEtaB = A * Math.Cos(etaB);
double bSinEtaB = B * Math.Sin(etaB);
double xB = Cx + aCosEtaB * _cosTheta - bSinEtaB * _sinTheta;
double yB = Cy + aCosEtaB * _sinTheta + bSinEtaB * _cosTheta;
//maximal error point
double aCosEta = A * Math.Cos(eta);
double bSinEta = B * Math.Sin(eta);View on GitHub (pinned to 11c5427268)
Solutions
- Pass a degree in [1, _maxDegree]; check the current max via the value you set with SetMaxDegree.
- Loop only over valid degrees: for (int d = 1; d <= maxDegree; d++) ... and pick the smallest whose error is under threshold.
- Initialize degree explicitly rather than relying on default(int) (0).
Example fix
// before
for (int d = 0; d <= 4; d++)
err = arc.EstimateError(d, a, b);
// after
for (int d = 1; d <= maxDegree; d++)
err = arc.EstimateError(d, a, b); Defensive patterns
Strategy: validation
Validate before calling
var d = Math.Clamp(degree, 1, maxDegree); var err = arc.EstimateError(d, etaA, etaB);
Type guard
static bool IsValidDegree(int d, int max) => d >= 1 && d <= max;
Prevention
- Loop degrees in [1, maxDegree] only.
- Keep the degree you pass to EstimateError consistent with SetMaxDegree.
When it happens
Trigger: arc.EstimateError(0, etaA, etaB), arc.EstimateError(4, etaA, etaB), or calling with degree 3 after SetMaxDegree(2).
Common situations: Looping over candidate degrees without bounds; calling EstimateError with a degree higher than the configured max; passing an uninitialized degree variable (0).
Related errors
- maxDegree must be between 1 and 3
- defaultFlatness must be greater than 1.0e-10
- Invalid bool rule.
- Invalid bool rule
- points
AI-assisted analysis of AvaloniaUI/Avalonia@11c5427268 (2026-08-13).
Data as JSON: /api/errors/61c351a8a0a8a7d1.
Report an issue: GitHub.