Fix multiplying TextureBrush with a disposed matrix on Unix (dotnet/corefx#24109)
authorHugh Bellamy <hughbellars@gmail.com>
Tue, 19 Sep 2017 21:28:44 +0000 (22:28 +0100)
committerEric Mellino <erme@microsoft.com>
Tue, 19 Sep 2017 21:28:44 +0000 (14:28 -0700)
* Fix multiplying TextureBrush with a disposed matrix on Unix

* Enable another passing test

* Fix accidentally committed file

Commit migrated from https://github.com/dotnet/corefx/commit/15f9a31fd45f9a7d667765ef08ecfd1cefddde3a

src/libraries/System.Drawing.Common/src/System/Drawing/TextureBrush.cs
src/libraries/System.Drawing.Common/tests/TextureBrushTests.cs

index c39f329..1710dfb 100644 (file)
@@ -168,7 +168,7 @@ namespace System.Drawing
             {
                 if (value == null)
                 {
-                    throw new ArgumentNullException("value");
+                    throw new ArgumentNullException(nameof(value));
                 }
 
                 int status = SafeNativeMethods.Gdip.GdipSetTextureTransform(new HandleRef(this, NativeBrush), new HandleRef(value, value.nativeMatrix));
@@ -225,6 +225,13 @@ namespace System.Drawing
                 throw new ArgumentNullException(nameof(matrix));
             }
 
+            // Multiplying the transform by a disposed matrix is a nop in GDI+, but throws
+            // with the libgdiplus backend. Simulate a nop for compatability with GDI+.
+            if (matrix.nativeMatrix == IntPtr.Zero)
+            {
+                return;
+            }
+
             int status = SafeNativeMethods.Gdip.GdipMultiplyTextureTransform(new HandleRef(this, NativeBrush),
                                                               new HandleRef(matrix, matrix.nativeMatrix),
                                                               order);
index bb93324..02e3e4c 100644 (file)
@@ -294,7 +294,6 @@ namespace System.Drawing.Tests
             AssertExtensions.Throws<ArgumentException>(null, () => new TextureBrush(image, WrapMode.Tile, Rectangle.Empty));
         }
 
-        [ActiveIssue(20884, TestPlatforms.AnyUnix)]
         [ConditionalTheory(Helpers.GdiplusIsAvailable)]
         [InlineData(WrapMode.Tile - 1)]
         [InlineData(WrapMode.Clamp + 1)]
@@ -431,7 +430,6 @@ namespace System.Drawing.Tests
             }
         }
 
-        [ActiveIssue(20884, TestPlatforms.AnyUnix)]
         [ConditionalFact(Helpers.GdiplusIsAvailable)]
         public void MultiplyTransform_DisposedMatrix_Nop()
         {
@@ -662,7 +660,6 @@ namespace System.Drawing.Tests
             }
         }
 
-        [ActiveIssue(20884, TestPlatforms.AnyUnix)]
         [ConditionalFact(Helpers.GdiplusIsAvailable)]
         public void Transform_SetNull_ThrowsArgumentNullException()
         {
@@ -786,7 +783,6 @@ namespace System.Drawing.Tests
             }
         }
 
-        [ActiveIssue(20884, TestPlatforms.AnyUnix)]
         [ConditionalTheory(Helpers.GdiplusIsAvailable)]
         [InlineData(WrapMode.Tile - 1)]
         [InlineData(WrapMode.Clamp + 1)]