Skip to content

Commit c0e6f40

Browse files
Add defensive NaN checks for Canvas position values in eraser tool
Co-authored-by: RuntimeRascal <2422222+RuntimeRascal@users.noreply.github.com>
1 parent 67cee0d commit c0e6f40

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

Src/GhostDraw/Tools/EraserTool.cs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,23 +141,35 @@ private void EraseAtPosition(Point position, Canvas canvas)
141141
// Check if eraser intersects with rectangle bounds
142142
double left = Canvas.GetLeft(rectangle);
143143
double top = Canvas.GetTop(rectangle);
144-
Rect shapeRect = new Rect(left, top, rectangle.Width, rectangle.Height);
145144

146-
if (eraserRect.IntersectsWith(shapeRect))
145+
// Handle NaN values (shouldn't happen, but be defensive)
146+
if (!double.IsNaN(left) && !double.IsNaN(top) &&
147+
!double.IsNaN(rectangle.Width) && !double.IsNaN(rectangle.Height))
147148
{
148-
shouldErase = true;
149+
Rect shapeRect = new Rect(left, top, rectangle.Width, rectangle.Height);
150+
151+
if (eraserRect.IntersectsWith(shapeRect))
152+
{
153+
shouldErase = true;
154+
}
149155
}
150156
}
151157
else if (element is Ellipse ellipse)
152158
{
153159
// Check if eraser intersects with ellipse bounds
154160
double left = Canvas.GetLeft(ellipse);
155161
double top = Canvas.GetTop(ellipse);
156-
Rect ellipseRect = new Rect(left, top, ellipse.Width, ellipse.Height);
157162

158-
if (eraserRect.IntersectsWith(ellipseRect))
163+
// Handle NaN values (shouldn't happen, but be defensive)
164+
if (!double.IsNaN(left) && !double.IsNaN(top) &&
165+
!double.IsNaN(ellipse.Width) && !double.IsNaN(ellipse.Height))
159166
{
160-
shouldErase = true;
167+
Rect ellipseRect = new Rect(left, top, ellipse.Width, ellipse.Height);
168+
169+
if (eraserRect.IntersectsWith(ellipseRect))
170+
{
171+
shouldErase = true;
172+
}
161173
}
162174
}
163175

0 commit comments

Comments
 (0)