Skip to content

[Android] GraphicsView: prevent TapGesture crash when previous touch points are empty#34348

Closed
michalpobuta wants to merge 1 commit intodotnet:mainfrom
michalpobuta:Issue34296
Closed

[Android] GraphicsView: prevent TapGesture crash when previous touch points are empty#34348
michalpobuta wants to merge 1 commit intodotnet:mainfrom
michalpobuta:Issue34296

Conversation

@michalpobuta
Copy link
Copy Markdown
Contributor

Summary

Fixes an Android crash path in PlatformTouchGraphicsView.TouchesMoved when previous touch points can be empty.

  • Updated src/Core/src/Platform/Android/PlatformTouchGraphicsView.cs
    • Changed guard from points.Length == 1 to _lastMovedViewPoints.Length > 0 before reading _lastMovedViewPoints[0].

Tests

Added/updated Issue34296 UI test coverage:

  • src/Controls/tests/TestCases.HostApp/Issues/Issue34296.cs
  • src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue34296.cs

Test verifies tapping the GraphicsView twice updates the status label to TapCount:2 and does not crash.

Local Validation

./.dotnet/dotnet tool run pwsh .github/scripts/BuildAndRunHostApp.ps1 -Platform android -TestFilter "Issue34296"

Result: ✅ All tests passed (SUCCESS) on Android

Issues fixed

Fixes #34296

Platforms Affected

  • ✅ Android

Copilot AI review requested due to automatic review settings March 5, 2026 11:24
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 5, 2026

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 34348

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 34348"

@dotnet-policy-service dotnet-policy-service bot added the community ✨ Community Contribution label Mar 5, 2026
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

Hey there @@michalpobuta! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes an Android crash in PlatformTouchGraphicsView.TouchesMoved that can occur when prior touch points are empty, and adds an Issue34296 UI test to validate tapping a GraphicsView does not crash.

Changes:

  • Android: Adjusted the TouchesMoved drag-start guard to avoid indexing into an empty “previous points” array.
  • Tests (HostApp): Added an Issue34296 page with a GraphicsView + TapGestureRecognizer to exercise the crash path.
  • Tests (Shared): Added an Issue34296 NUnit/Appium test that taps the GraphicsView twice and verifies TapCount:2.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/Core/src/Platform/Android/PlatformTouchGraphicsView.cs Updates the move/drag guard logic intended to prevent the crash when previous touch points are empty.
src/Controls/tests/TestCases.HostApp/Issues/Issue34296.cs Adds a repro page with a tappable GraphicsView and status label used by the UI test.
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue34296.cs Adds an Appium-based UITest that taps the GraphicsView twice and asserts the tap count text.
Comments suppressed due to low confidence (1)

src/Core/src/Platform/Android/PlatformTouchGraphicsView.cs:96

  • The new guard prevents _lastMovedViewPoints[0] from throwing when the previous points were empty, but this block still reads points[0] unconditionally and also changes the original single-touch behavior (points.Length == 1). Consider guarding on both arrays (e.g., require points.Length > 0 and preserve the original single-touch check) so multi-touch moves aren’t accidentally treated as a small-delta tap and empty points can’t crash this method (it’s public and can be called directly).
				if (_lastMovedViewPoints.Length > 0)
				{
					float deltaX = _lastMovedViewPoints[0].X - points[0].X;
					float deltaY = _lastMovedViewPoints[0].Y - points[0].Y;


You can also share your feedback on Copilot code review. Take the survey.

App.WaitForElement("Issue34296StatusLabel");

App.Tap("Issue34296GraphicsView");

Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To reduce UI test flakiness, consider waiting for the label to reach the expected value after the second tap (e.g., WaitForTextToBePresentInElement on Issue34296StatusLabel with TapCount:2) before calling GetText() and asserting. Reading immediately after App.Tap can race the UI update on slower devices.

Suggested change
App.WaitForTextToBePresentInElement("Issue34296StatusLabel", "TapCount:2");

Copilot uses AI. Check for mistakes.
Comment on lines +53 to +54
}
#endif
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This page is intended to exercise the specific Android crash path by calling TouchesBegan(Array.Empty<PointF>()) followed by TouchesMoved(...). Right now, if graphicsView.Handler/PlatformView isn’t the expected PlatformTouchGraphicsView for any reason, the test will still pass and won’t actually validate the fix. Consider making this explicit (e.g., update the status label to an error state or throw in DEBUG when the platform view isn’t found) so the UITest can fail if the reproduction path wasn’t executed.

Suggested change
}
#endif
}
else
{
#if DEBUG
throw new InvalidOperationException("Issue34296: Expected PlatformTouchGraphicsView as PlatformView but it was not found.");
#else
_statusLabel.Text = "Error: PlatformTouchGraphicsView not found";
return;
#endif
}
#endif

Copilot uses AI. Check for mistakes.
@kubaflo
Copy link
Copy Markdown
Contributor

kubaflo commented Mar 5, 2026

Duplicate of #34301

@kubaflo kubaflo marked this as a duplicate of #34301 Mar 5, 2026
@kubaflo kubaflo closed this Mar 5, 2026
@github-actions github-actions bot locked and limited conversation to collaborators Apr 5, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

community ✨ Community Contribution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TapGestureRecognizer on GraphicsView causes a crash on Android devices

3 participants