From d7bbd9d248e871a57212a025e1adbc5ba42a52ae Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 25 Oct 2022 18:25:50 +0200 Subject: [PATCH] When the control is not effectively visible the matrix could be null --- src/AvaloniaEdit/Utils/ExtensionMethods.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/AvaloniaEdit/Utils/ExtensionMethods.cs b/src/AvaloniaEdit/Utils/ExtensionMethods.cs index 7fe4b896..fd5b0900 100644 --- a/src/AvaloniaEdit/Utils/ExtensionMethods.cs +++ b/src/AvaloniaEdit/Utils/ExtensionMethods.cs @@ -224,6 +224,9 @@ public static Point SnapToDevicePixels(this Point p, IVisual targetVisual) // Create a matrix to translate from control coordinates to device coordinates. var m = targetVisual.TransformToVisual((Control)root) * Matrix.CreateScale(scaling); + if (m == null) + return p; + // Translate the point to device coordinates. var devicePoint = p.Transform(m.Value);