{"record":{"id":"808446d6f4a4ad7c","repo":"dotnet/wpf","slug":"sr-invalidmatrixcontainsinfinity","errorCode":null,"errorMessage":"SR.InvalidMatrixContainsInfinity","messagePattern":"SR\\.InvalidMatrixContainsInfinity","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Ink/Stroke.cs","lineNumber":152,"sourceCode":"        /// <param name=\"applyToStylusTip\">Boolean if true the transform matrix will be applied to StylusTip</param>\n        public virtual void Transform(Matrix transformMatrix, bool applyToStylusTip)\n        {\n            if (transformMatrix.IsIdentity)\n            {\n                return;\n            }\n\n            if (!transformMatrix.HasInverse)\n            {\n                throw new ArgumentException(SR.MatrixNotInvertible, nameof(transformMatrix));\n            }\n            else if ( MatrixHelper.ContainsNaN(transformMatrix))\n            {\n                throw new ArgumentException(SR.InvalidMatrixContainsNaN, nameof(transformMatrix));\n            }\n            else if ( MatrixHelper.ContainsInfinity(transformMatrix))\n            {\n                throw new ArgumentException(SR.InvalidMatrixContainsInfinity, nameof(transformMatrix));\n            }\n            else\n            {\n                // we need to force a recaculation of the cached path geometry right after the\n                // DrawingAttributes changed, beforet the events are raised.\n                _cachedGeometry = null;\n                // Set the cached bounds to empty, which will force a re-calculation of the _cachedBounds upon next GetBounds call.\n                _cachedBounds = Rect.Empty;\n\n                if (applyToStylusTip)\n                {\n                    //we use this flag to prevent this method from causing two\n                    //invalidates, which causes a good deal of memory thrash when\n                    //the strokes are being rendered\n                    _delayRaiseInvalidated = true;\n                }\n\n                try","sourceCodeStart":134,"sourceCodeEnd":170,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Ink/Stroke.cs#L134-L170","documentation":"Stroke.Transform(Matrix) rejects matrices containing infinite (PositiveInfinity/NegativeInfinity) values via MatrixHelper.ContainsInfinity. Infinite coordinates cannot define a valid transform, so an ArgumentException naming transformMatrix is thrown before modifying the stroke's cached geometry or bounds.","triggerScenarios":"Calling stroke.Transform(m) where any matrix coefficient is +/-Infinity — usually from division by a zero scale/dimension or overflow in matrix composition.","commonSituations":"Dividing by a zero zoom factor computed from UI size; zoom-to-fit math on a zero-area content; numeric overflow in repeated matrix multiplication.","solutions":["Check MatrixHelper.ContainsInfinity (and NaN) before Transform and clamp or correct the source computation","Fix the upstream division producing infinity (guard denominator != 0)","Substitute a bounded matrix (e.g. Matrix.Identity) when the computed transform is non-finite"],"exampleFix":"// before\nstroke.Transform(zoomMatrix); // may contain Infinity\n// after\nif (double.IsFinite(zoomMatrix.M11) && zoomMatrix.HasInverse)\n    stroke.Transform(zoomMatrix);","handlingStrategy":"validation","validationCode":"if (!MatrixHelper.ContainsInfinity(matrix) && matrix.HasInverse) stroke.Transform(matrix);","typeGuard":"bool IsFiniteMatrix(Matrix m) => double.IsFinite(m.M11) && double.IsFinite(m.M12) && double.IsFinite(m.M21) && double.IsFinite(m.M22) && double.IsFinite(m.OffsetX) && double.IsFinite(m.OffsetY);","tryCatchPattern":null,"preventionTips":["Guard denominators (zoom factors, sizes) against zero before computing the matrix","Clamp computed scale values to a bounded range","Validate matrix finiteness before composing with stroke transforms"],"tags":["wpf","ink","matrix","infinity","argument-exception"],"backgroundTag":"invalid-argument-value","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"}