macOS: Avoid modifying hash while iterating it

QCocoaTouch sneakily updated the list of active touches in the
destructor, causing problems when we switched from Q_FOREACH
to ranged-for.

Fixes: QTBUG-83876
Change-Id: If7ec9e9116b7eb581580b461ae12ad70c739906d
Reviewed-by: Simon Hausmann <hausmann@gmail.com>
This commit is contained in:
Tor Arne Vestbø 2020-04-29 19:14:06 +02:00
parent e6a39c13bf
commit 042b118caf

View File

@ -184,7 +184,10 @@ QCocoaTouch::getCurrentTouchPointList(NSEvent *event, bool acceptSingleTouch)
if (_touchCount != _currentTouches.size()) {
// Remove all instances, and basically start from scratch:
touchPoints.clear();
for (QCocoaTouch *qcocoaTouch : _currentTouches) {
// Deleting touch points will remove them from current touches,
// so we make a copy of the touches before iterating them.
const auto currentTouchesSnapshot = _currentTouches;
for (QCocoaTouch *qcocoaTouch : currentTouchesSnapshot) {
if (!_updateInternalStateOnly) {
qcocoaTouch->_touchPoint.state = Qt::TouchPointReleased;
touchPoints.insert(qcocoaTouch->_touchPoint.id, qcocoaTouch->_touchPoint);