summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPiotr Mikolajczyk <piotr.mikolajczyk@qt.io>2020-09-29 10:41:23 +0200
committerPiotr Mikolajczyk <piotr.mikolajczyk@qt.io>2020-10-28 08:12:34 +0000
commit4fe9e0ed027134a833b2243597a2ccd00987b559 (patch)
treede4af1dc3284f8eba6d3bc3449545ae86e700fce
parent3e366ddf164acd9764f5d66658426d05460d3403 (diff)
downloadqtlocation-4fe9e0ed027134a833b2243597a2ccd00987b559.tar.gz
Fix crash when showing Map QML comp. for 2nd+ time
Crash caused by storing pointer to a node that could be deleted elsewhere Fixes: QTBUG-85260 Change-Id: I871123322fac84b8bf91e9bab8ecad08e75c2854 Reviewed-by: Paolo Angelelli <paolo.angelelli.qt@gmail.com>
-rw-r--r--src/location/labs/qsg/qgeomapobjectqsgsupport.cpp29
1 files changed, 28 insertions, 1 deletions
diff --git a/src/location/labs/qsg/qgeomapobjectqsgsupport.cpp b/src/location/labs/qsg/qgeomapobjectqsgsupport.cpp
index 0e1df8f6..cd180130 100644
--- a/src/location/labs/qsg/qgeomapobjectqsgsupport.cpp
+++ b/src/location/labs/qsg/qgeomapobjectqsgsupport.cpp
@@ -48,7 +48,32 @@ static int findMapObject(QGeoMapObject *o, const QList<MapObject> &list)
}
return -1;
}
+namespace {
+bool findNodeInStructure(QSGNode *root, QSGNode *item)
+{
+ if (root == nullptr || item == nullptr)
+ return false;
+ if (root == item)
+ return true;
+ auto currentChild = root->firstChild();
+ // First check the direct child nodes and if not found let's dive deeper
+ bool bFound = (item == currentChild);
+
+ while (!bFound && currentChild) {
+ currentChild = currentChild->nextSibling();
+ bFound = (item == currentChild);
+ }
+ if (!bFound) {
+ currentChild = root->firstChild();
+ while (!bFound && currentChild) {
+ bFound = findNodeInStructure(currentChild, item);
+ currentChild = currentChild->nextSibling();
+ }
+ }
+ return bFound;
+}
+}
bool QGeoMapObjectQSGSupport::createMapObjectImplementation(QGeoMapObject *obj, QGeoMapPrivate *d)
{
QExplicitlySharedDataPointer<QGeoMapObjectPrivate> pimpl =
@@ -157,9 +182,11 @@ void QGeoMapObjectQSGSupport::updateMapObjects(QSGNode *root, QQuickWindow *wind
{
if (!root)
return;
+ if (!findNodeInStructure(root, m_mapObjectsRootNode))
+ m_mapObjectsRootNode = nullptr;
if (!m_mapObjectsRootNode) {
m_mapObjectsRootNode = new QDeclarativePolygonMapItemPrivateOpenGL::RootNode();
- root->appendChildNode(m_mapObjectsRootNode);
+ root->appendChildNode(m_mapObjectsRootNode); // PASSING OWNERSHIP!
}
m_mapObjectsRootNode->removeAllChildNodes();