summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2020-04-29 19:14:06 +0200
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2020-04-30 08:40:49 +0200
commit042b118cafc68c677e9eafa7f718a025a34940da (patch)
treed4b6b04aaccef2646979808e511a00282544f126 /src
parente6a39c13bfe44719ee345419e98638e5f38fe7ee (diff)
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>
Diffstat (limited to 'src')
-rw-r--r--src/plugins/platforms/cocoa/qmultitouch_mac.mm5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/plugins/platforms/cocoa/qmultitouch_mac.mm b/src/plugins/platforms/cocoa/qmultitouch_mac.mm
index 95256657fe..ac2317b217 100644
--- a/src/plugins/platforms/cocoa/qmultitouch_mac.mm
+++ b/src/plugins/platforms/cocoa/qmultitouch_mac.mm
@@ -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);