{"record":{"id":"3aed6d4a49141ae7","repo":"AvaloniaUI/Avalonia","slug":"invalid-render-scaling-value-scaling","errorCode":null,"errorMessage":"Invalid render scaling value {scaling}","messagePattern":"Invalid render scaling value (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Layout/LayoutHelper.cs","lineNumber":267,"sourceCode":"            return dpiScale == 1.0 ?\n                Math.Ceiling(value) :\n                Math.Ceiling(RoundTo8Digits(value) * dpiScale) / dpiScale;\n        }\n\n        [MethodImpl(MethodImplOptions.AggressiveInlining)]\n        private static double RoundTo8Digits(double value)\n        {\n            // Round the value to avoid FP errors. This is needed because if `value` has a floating\n            // point precision error (e.g. 79.333333333333343) then when it's multiplied by\n            // `dpiScale` and rounded up, it will be rounded up to a value one greater than it\n            // should be.\n            return Math.Round(value, 8, MidpointRounding.ToZero);\n        }\n\n        internal static double ValidateScaling(double scaling)\n        {\n            if (MathUtilities.IsNegativeOrNonFinite(scaling) || MathUtilities.IsZero(scaling))\n                throw new InvalidOperationException($\"Invalid render scaling value {scaling}\");\n\n            if (MathUtilities.IsOne(scaling))\n            {\n                // Ensure we've got exactly 1.0 and not an approximation,\n                // so we don't have to use MathUtilities.IsOne in various layout hot paths.\n                return 1.0;\n            }\n\n            return scaling;\n        }\n    }\n}\n","sourceCodeStart":249,"sourceCodeEnd":280,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Layout/LayoutHelper.cs#L249-L280","documentation":"ValidateScaling throws when the render/DPI scaling factor is zero, negative, or non-finite (NaN/Infinity). LayoutHelper.ValidateScaling guards every layout hot path so that a bogus scaling value never propagates into pixel-snapping math (RoundTo8Digits) which would produce corrupt layout geometry. A valid scaling value must be a strictly-positive finite double.","triggerScenarios":"An internal or platform call to LayoutHelper.ValidateScaling(scaling) where scaling is 0, negative, NaN, or Infinity. Typically reached during layout/render setup when the platform reports an invalid DPI scale, or when a custom render target returns a degenerate scaling value.","commonSituations":"Headless/server environment where the platform DPI provider returns 0. A misconfigured test environment or mock platform returning NaN. A monitor/reporting edge case on certain Linux/Wayland setups returning unexpected scale. Passing `double.NaN` through a scaling binding.","solutions":["Check the platform DPI scale provider implementation — it must return a strictly positive finite value.","In tests/headless scenarios, ensure the test host (e.g. Avalonia.Headless) is configured and provides a valid scale.","Guard the scaling value before it reaches layout: if non-positive or non-finite, substitute a safe default like 1.0.","Inspect the call stack to find which platform/render layer supplied the degenerate value and fix it at the source."],"exampleFix":"// before\ndouble scale = GetScaleFromPlatform(); // returns 0 or NaN in headless\n\n// after\ndouble scale = GetScaleFromPlatform();\nif (double.IsNaN(scale) || scale <= 0) scale = 1.0;","handlingStrategy":"validation","validationCode":"static double SafeScale(double scale) =>\n    double.IsNaN(scale) || double.IsInfinity(scale) || scale <= 0 ? 1.0 : scale;\n\n// usage before any layout/render code expecting a scale\nvar safe = SafeScale(reportedScale);","typeGuard":null,"tryCatchPattern":"try\n{\n    LayoutHelper.ValidateScaling(scaling);\n}\ncatch (InvalidOperationException)\n{\n    scaling = 1.0; // fall back to identity scale\n    LayoutHelper.ValidateScaling(scaling);\n}","preventionTips":["In headless/test environments, configure the test host to provide a valid scale.","Never pass uninitialized or computed-without-guard scaling values to layout APIs.","Wrap platform DPI providers so they clamp degenerate values to 1.0."],"tags":["layout","rendering","dpi","scaling","platform"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}