{"record":{"id":"47cba05ee27d5999","repo":"dotnet/wpf","slug":"sr-invalidpressurevalue","errorCode":null,"errorMessage":"SR.InvalidPressureValue","messagePattern":"SR\\.InvalidPressureValue","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Common/StylusPoint.cs","lineNumber":84,"sourceCode":"            int[] additionalValues, \n            bool validateAdditionalData,\n            bool validatePressureFactor)\n        {\n            if (Double.IsNaN(x))\n            {\n                throw new ArgumentOutOfRangeException(nameof(x), SR.InvalidStylusPointXYNaN);\n            }\n            if (Double.IsNaN(y))\n            {\n                throw new ArgumentOutOfRangeException(nameof(y), SR.InvalidStylusPointXYNaN);\n            }\n\n\n            //we don't validate pressure when called by StylusPointDescription.Reformat\n            if (validatePressureFactor &&\n                (pressureFactor == Single.NaN || pressureFactor < 0.0f || pressureFactor > 1.0f))\n            {\n                throw new ArgumentOutOfRangeException(nameof(pressureFactor), SR.InvalidPressureValue);\n            }\n            //\n            // only accept values between MaxXY and MinXY\n            // we don't throw when passed a value outside of that range, we just silently trunctate\n            //\n            _x = GetClampedXYValue(x);\n            _y = GetClampedXYValue(y);\n            _stylusPointDescription = stylusPointDescription;\n            _additionalValues = additionalValues;\n            _pressureFactor = pressureFactor;\n\n            if (validateAdditionalData)\n            {\n                //\n                // called from the public verbose ctor\n                //\n                ArgumentNullException.ThrowIfNull(stylusPointDescription);\n","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Common/StylusPoint.cs#L66-L102","documentation":"The StylusPoint constructor throws ArgumentOutOfRangeException when the pressureFactor is NaN, negative, or greater than 1.0. Pressure is stored as a float in the normalized range [0, 1]; values outside it are meaningless, so the constructor rejects them (unless validation is disabled internally, as in StylusPointDescription.Reformat).","triggerScenarios":"Calling new StylusPoint(x, y, pressureFactor, ...) with a pressureFactor that is float.NaN, < 0.0f, or > 1.0f.","commonSituations":"Passing raw device pressure (e.g. 0-1024 or 0-255 integer ranges) without normalizing to 0..1, or NaN from uninitialized float fields.","solutions":["Normalize raw pressure to [0,1]: pressureFactor = rawPressure / maxPressure.","Clamp: Math.Clamp(rawPressure, 0f, 1f) before constructing.","Catch ArgumentOutOfRangeException if untrusted pressure data must be handled gracefully."],"exampleFix":"// before\nvar point = new StylusPoint(x, y, rawPressure);\n// after\nfloat pressure = Math.Clamp(rawPressure / 1024f, 0f, 1f);\nvar point = new StylusPoint(x, y, pressure);","handlingStrategy":"validation","validationCode":"if (float.IsNaN(pressureFactor) || pressureFactor < 0f || pressureFactor > 1f)\n    throw new ArgumentException(\"pressureFactor must be in [0,1]\");","typeGuard":"static bool IsValidPressure(float p) => !float.IsNaN(p) && p >= 0f && p <= 1f;","tryCatchPattern":"try { var p = new StylusPoint(x, y, pf, desc, vals); }\ncatch (ArgumentOutOfRangeException ex) when (ex.ParamName == \"pressureFactor\") { /* clamp and retry */ }","preventionTips":["Always normalize raw device pressure to [0,1]","Use Math.Clamp on pressure inputs","Never pass uninitialized float fields as pressure"],"tags":["wpf","stylus","argumentoutofrange","pressure"],"backgroundTag":"value-out-of-range","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}