From a6a9a65e3ac7d1cd255cbe74df7070c091941216 Mon Sep 17 00:00:00 2001 From: Kirill Burtsev Date: Wed, 28 Oct 2020 14:26:05 +0100 Subject: Fix rare duplicate ids forming in touch point id's mapping QTouchEvent may contain touch point release and press simultaneously in this particular order. Hence if mapping for released point is deleted before id is chosen for pressed one, output transformed list may contain points with same ids. Since new touch points delivered before released one, this will lead to assert in chromium about duplicate ids. Change-Id: I209d7d8c752c7bd74d2580ef65478c92e54cb099 Reviewed-by: Allan Sandfeld Jensen --- src/core/render_widget_host_view_qt.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/core/render_widget_host_view_qt.cpp') diff --git a/src/core/render_widget_host_view_qt.cpp b/src/core/render_widget_host_view_qt.cpp index 525e9924e..f8e20d188 100644 --- a/src/core/render_widget_host_view_qt.cpp +++ b/src/core/render_widget_host_view_qt.cpp @@ -1251,6 +1251,7 @@ void RenderWidgetHostViewQt::processMotionEvent(const ui::MotionEvent &motionEve QList RenderWidgetHostViewQt::mapTouchPointIds(const QList &inputPoints) { + QList idsToRemove; QList outputPoints = inputPoints; for (int i = 0; i < outputPoints.size(); ++i) { QTouchEvent::TouchPoint &point = outputPoints[i]; @@ -1262,9 +1263,14 @@ QList RenderWidgetHostViewQt::mapTouchPointIds(const QL point.setId(it.value()); if (point.state() == Qt::TouchPointReleased) - m_touchIdMapping.remove(qtId); + idsToRemove.append(qtId); } + for (int qtId : qAsConst(idsToRemove)) + m_touchIdMapping.remove(qtId); + + Q_ASSERT(outputPoints.size() == std::accumulate(outputPoints.cbegin(), outputPoints.cend(), QSet(), + [] (QSet s, const QTouchEvent::TouchPoint &p) { s.insert(p.id()); return s; }).size()); return outputPoints; } -- cgit v1.2.3