AvaloniaUI/Avalonia · error · ArgumentException
defaultFlatness must be greater than 1.0e-10
Error message
defaultFlatness must be greater than 1.0e-10
What it means
Thrown by SetDefaultFlatness when the requested flatness (the acceptable approximation error tolerance) is below 1.0e-10. The error-estimation math relies on flatness being a positive, non-degenerate magnitude; an extremely small value would demand unbounded subdivision and destabilize the rational-function error bounds.
Source
Thrown at src/Avalonia.Base/Media/PreciseEllipticArcHelper.cs:436
public void SetMaxDegree(int maxDegree)
{
if (maxDegree < 1 || maxDegree > 3)
{
throw new ArgumentException(@"maxDegree must be between 1 and 3", nameof(maxDegree));
}
_maxDegree = maxDegree;
}
/// <summary>
/// Sets the default flatness for Bezier curve approximation
/// </summary>
/// <param name="defaultFlatness">default flatness (must be greater than 1e-10)</param>
/// <exception cref="ArgumentException">Thrown if defaultFlatness is lower than 1e-10</exception>
public void SetDefaultFlatness(double defaultFlatness)
{
if (defaultFlatness < 1.0E-10)
{
throw new ArgumentException(@"defaultFlatness must be greater than 1.0e-10", nameof(defaultFlatness));
}
_defaultFlatness = defaultFlatness;
}
/// <summary>
/// Computes the locations of the focii
/// </summary>
private void ComputeFocii()
{
double d = Math.Sqrt(A * A - B * B);
double dx = d * _cosTheta;
double dy = d * _sinTheta;
FirstFocusX = Cx - dx;
FirstFocusY = Cy - dy;
SecondFocusX = Cx + dx;
SecondFocusY = Cy + dy;
}
View on GitHub (pinned to 11c5427268)
Solutions
- Use a flatness at or above 1e-10 (typical rendering values are ~0.25 to 1.0 in device units).
- Floor the input: var f = Math.Max(userFlatness, 1e-10); arc.SetDefaultFlatness(f);
- If 'maximum precision' is requested, pick a small-but-valid tolerance like 1e-9 rather than 0.
Example fix
// before arc.SetDefaultFlatness(0); // intended 'max precision' // after arc.SetDefaultFlatness(1e-9); // small but valid tolerance
Defensive patterns
Strategy: validation
Validate before calling
var f = Math.Max(defaultFlatness, 1e-10); arc.SetDefaultFlatness(f);
Type guard
static bool IsValidFlatness(double f) => f >= 1.0e-10;
Prevention
- Floor flatness at 1e-10; use realistic tolerances (~0.25-1.0 device units) for rendering.
- Never pass 0 as a 'max precision' sentinel.
When it happens
Trigger: arc.SetDefaultFlatness(0) or arc.SetDefaultFlatness(1e-12) — any value strictly less than 1e-10, including zero and negatives.
Common situations: Exposing flatness as a user/config value without a floor; passing a 'max precision' sentinel of 0 expecting 'as precise as possible'; unit confusion (passing pixels-vs-device units).
Related errors
- maxDegree must be between 1 and 3
- degree should be between {1} and {_maxDegree}
- Animator has no property specified.
- Animator has no property specified.
- Animator has no property specified.
AI-assisted analysis of AvaloniaUI/Avalonia@11c5427268 (2026-08-13).
Data as JSON: /api/errors/1de17511c31d2817.
Report an issue: GitHub.