Skip to content

Commit 633262b

Browse files
[release/9.0] Fix issue 12538: Infinite loop in System.Drawing.Graphics between IsVisible(Point) and IsVisible(int, int) (#12550)
* Fix issue 12538: Infinite loop in System.Drawing.Graphics between IsVisible(Point) and IsVisible(int, int) * Add unit test --------- Co-authored-by: Olina Zhang (Beyondsoft Corporation) <[email protected]>
1 parent 6911289 commit 633262b

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

src/System.Drawing.Common/src/System/Drawing/Graphics.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ public void ExcludeClip(Region region)
583583

584584
public void TranslateClip(int dx, int dy) => CheckStatus(PInvoke.GdipTranslateClip(NativeGraphics, dx, dy));
585585

586-
public bool IsVisible(int x, int y) => IsVisible(new Point(x, y));
586+
public bool IsVisible(int x, int y) => IsVisible((float)x, y);
587587

588588
public bool IsVisible(Point point) => IsVisible(point.X, point.Y);
589589

src/System.Drawing.Common/tests/System/Drawing/GraphicsTests.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2818,6 +2818,45 @@ private static void VerifyGraphics(Graphics graphics, RectangleF expectedVisible
28182818
Assert.Equal(expectedVisibleClipBounds, graphics.VisibleClipBounds);
28192819
}
28202820

2821+
[Fact]
2822+
public void IsVisible_AllOverloads_ReturnSameResult()
2823+
{
2824+
using Bitmap bitmap = new(100, 100);
2825+
using Graphics graphics = Graphics.FromImage(bitmap);
2826+
2827+
// Test points
2828+
Point point = new(10, 10);
2829+
PointF pointF = new(10.5f, 10.5f);
2830+
int x = 10, y = 10;
2831+
float fx = 10.5f, fy = 10.5f;
2832+
2833+
// Test rectangles
2834+
Rectangle rect = new(10, 10, 50, 50);
2835+
RectangleF rectF = new(10.5f, 10.5f, 50.5f, 50.5f);
2836+
int width = 50, height = 50;
2837+
float fwidth = 50.5f, fheight = 50.5f;
2838+
2839+
// Verify that all overloads return the same result for points
2840+
bool result1 = graphics.IsVisible(x, y);
2841+
bool result2 = graphics.IsVisible(point);
2842+
bool result3 = graphics.IsVisible(fx, fy);
2843+
bool result4 = graphics.IsVisible(pointF);
2844+
2845+
result1.Should().Be(result2);
2846+
result1.Should().Be(result3);
2847+
result1.Should().Be(result4);
2848+
2849+
// Verify that all overloads return the same result for rectangles
2850+
bool result5 = graphics.IsVisible(x, y, width, height);
2851+
bool result6 = graphics.IsVisible(rect);
2852+
bool result7 = graphics.IsVisible(fx, fy, fwidth, fheight);
2853+
bool result8 = graphics.IsVisible(rectF);
2854+
2855+
result5.Should().Be(result6);
2856+
result5.Should().Be(result7);
2857+
result5.Should().Be(result8);
2858+
}
2859+
28212860
#if NET8_0_OR_GREATER
28222861
[Fact]
28232862
public void DrawCachedBitmap_ThrowsArgumentNullException()

0 commit comments

Comments
 (0)