Skip to content

Commit

Permalink
Properly handle touch events with no touch points
Browse files Browse the repository at this point in the history
Those can apparently happen on Android when putting your palm on the
screen, which in turn can cause crashes when accessing the out-of-bounds
first point.
  • Loading branch information
askmeaboutlo0m committed Nov 18, 2024
1 parent e75469a commit 68469a8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Unreleased Version 2.2.2-pre
* Feature: Make size adjustment canvas shortcut depend on the speed of the drag. Thanks MorrowShore for suggesting.
* Fix: Remove pointless permissions on Android that Qt includes by default but aren't actually used.
* Fix: Don't default Android to fingerpaint when a pen is present.
* Fix: Work around a crash on Android that sometimes occurs when putting your palm on the screen, which somehow leads to touch events with zero contact points. Thanks Mav for reporting.

2024-11-06 Version 2.2.2-beta.4
* Fix: Solve rendering glitches with selection outlines that happen on some systems. Thanks xxxx for reporting.
Expand Down
17 changes: 14 additions & 3 deletions src/desktop/utils/touchhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ void TouchHandler::handleTouchBegin(QTouchEvent *event)
{
const QList<compat::TouchPoint> &points = compat::touchPoints(*event);
int pointsCount = points.size();
// Can apparently happen on Android when putting your palm on the screen.
if(pointsCount == 0) {
return;
}

QPointF posf = compat::touchPos(points.first());

m_touchPos = QPointF(0.0, 0.0);
Expand Down Expand Up @@ -164,6 +169,11 @@ void TouchHandler::handleTouchUpdate(
{
const QList<compat::TouchPoint> &points = compat::touchPoints(*event);
int pointsCount = points.size();
// Can apparently happen on Android when putting your palm on the screen.
if(pointsCount == 0) {
return;
}

if(pointsCount > m_maxTouchPoints) {
m_maxTouchPoints = pointsCount;
}
Expand Down Expand Up @@ -357,9 +367,10 @@ void TouchHandler::handleTouchEnd(QTouchEvent *event, bool cancel)
qUtf8Printable(compat::debug(points)),
qulonglong(event->timestamp()));
flushTouchDrawBuffer();
emit touchReleased(
QDateTime::currentMSecsSinceEpoch(),
compat::touchPos(compat::touchPoints(*event).first()));
// No points can happen on Android when putting your palm on the screen.
QPointF posf =
points.isEmpty() ? m_touchPos : compat::touchPos(points.first());
emit touchReleased(QDateTime::currentMSecsSinceEpoch(), posf);
} else if(m_touchDragging) {
DP_EVENT_LOG(
"touch_%s touching=%d type=%d device=%s points=%s timestamp=%llu",
Expand Down

0 comments on commit 68469a8

Please sign in to comment.