From ab91ac09924f7e356e4d2b8cf40c89a3c12011bb Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Mon, 16 Mar 2020 13:29:22 +0100 Subject: 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 --- .../input/evdevtouch/qevdevtouchhandler.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'src/platformsupport/input') 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(0); - else - m_contacts.erase(it); + } else { + it = m_contacts.erase(it); + continue; + } } else { contact.state = Qt::TouchPointStationary; } + ++it; } m_lastContacts = m_contacts; -- cgit v1.2.3