diff options
author | Lars Knoll <lars.knoll@qt.io> | 2020-03-16 13:29:22 +0100 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2020-04-01 21:33:57 +0100 |
commit | ab91ac09924f7e356e4d2b8cf40c89a3c12011bb (patch) | |
tree | 809de6479064a91d3ecd7e6e09f3dda0212b9082 /src/platformsupport/input | |
parent | 605bda587e0d3b3eebb871a668ad6014cf843a10 (diff) |
Don't store iterators on QHash while erasing
QHash::erase() in the new QHash will invalidate
all iterators pointing into the hash.
Change-Id: Ia54e8485a947cd7274f832c7c8c624d0aaded4ba
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/platformsupport/input')
-rw-r--r-- | src/platformsupport/input/evdevtouch/qevdevtouchhandler.cpp | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/src/platformsupport/input/evdevtouch/qevdevtouchhandler.cpp b/src/platformsupport/input/evdevtouch/qevdevtouchhandler.cpp index 78728ef4ce..13829c040e 100644 --- a/src/platformsupport/input/evdevtouch/qevdevtouchhandler.cpp +++ b/src/platformsupport/input/evdevtouch/qevdevtouchhandler.cpp @@ -580,9 +580,7 @@ void QEvdevTouchScreenData::processInputEvent(input_event *data) Qt::TouchPointStates combinedStates; bool hasPressure = false; - for (auto i = m_contacts.begin(), end = m_contacts.end(); i != end; /*erasing*/) { - auto it = i++; - + for (auto it = m_contacts.begin(), end = m_contacts.end(); it != end; /*erasing*/) { Contact &contact(it.value()); if (!contact.state) @@ -605,7 +603,7 @@ void QEvdevTouchScreenData::processInputEvent(input_event *data) // Avoid reporting a contact in released state more than once. if (!m_typeB && contact.state == Qt::TouchPointReleased && !m_lastContacts.contains(key)) { - m_contacts.erase(it); + it = m_contacts.erase(it); continue; } @@ -613,6 +611,7 @@ void QEvdevTouchScreenData::processInputEvent(input_event *data) hasPressure = true; addTouchPoint(contact, &combinedStates); + ++it; } // Now look for contacts that have disappeared since the last sync. @@ -633,22 +632,23 @@ void QEvdevTouchScreenData::processInputEvent(input_event *data) } // Remove contacts that have just been reported as released. - for (auto i = m_contacts.begin(), end = m_contacts.end(); i != end; /*erasing*/) { - auto it = i++; - + for (auto it = m_contacts.begin(), end = m_contacts.end(); it != end; /*erasing*/) { Contact &contact(it.value()); if (!contact.state) continue; if (contact.state == Qt::TouchPointReleased) { - if (m_typeB) + if (m_typeB) { contact.state = static_cast<Qt::TouchPointState>(0); - else - m_contacts.erase(it); + } else { + it = m_contacts.erase(it); + continue; + } } else { contact.state = Qt::TouchPointStationary; } + ++it; } m_lastContacts = m_contacts; |