summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiikka Heikkinen <miikka.heikkinen@qt.io>2018-02-20 15:40:52 +0200
committerTomi Korpipää <tomi.korpipaa@qt.io>2018-02-21 04:24:19 +0000
commit152a43d9f7f29cb97629ec6141b48593a3c984f5 (patch)
treea3191707b009954cc37cf2f6027399558bf895b4
parent40a597216960072a25f178244e27d862bea5c61a (diff)
Clean up old objects when updating inspector panelv1.1.0-rc2
Old control elements were never deleted, which resulted in memory leak and more importantly signal connection leak. Obsolete connections of deleted objects could cause crashes. Task-number: QT3DS-1182 Change-Id: I24175dac3a78de77c5220d0837ec1c4b3dc480c0 Reviewed-by: Antti Määttä <antti.maatta@qt.io> Reviewed-by: Jere Tuliniemi <jere.tuliniemi@qt.io> Reviewed-by: Tomi Korpipää <tomi.korpipaa@qt.io>
-rw-r--r--src/Authoring/Studio/Palettes/Inspector/InspectorControlModel.cpp17
-rw-r--r--src/Authoring/Studio/Palettes/Inspector/InspectorControlModel.h2
2 files changed, 17 insertions, 2 deletions
diff --git a/src/Authoring/Studio/Palettes/Inspector/InspectorControlModel.cpp b/src/Authoring/Studio/Palettes/Inspector/InspectorControlModel.cpp
index da15c053..3b7194c7 100644
--- a/src/Authoring/Studio/Palettes/Inspector/InspectorControlModel.cpp
+++ b/src/Authoring/Studio/Palettes/Inspector/InspectorControlModel.cpp
@@ -585,8 +585,18 @@ auto InspectorControlModel::computeGroup(CInspectableBase* inspectable,
void InspectorControlModel::rebuildTree()
{
beginResetModel();
+ QVector<QObject *> deleteVector;
+ for (int i = 0; i < m_groupElements.count(); ++i) {
+ auto group = m_groupElements[i];
+ for (int p = 0; p < group.controlElements.count(); ++p)
+ deleteVector.append(group.controlElements[p].value<QObject *>());
+ }
m_groupElements = computeTree(m_inspectableBase);
endResetModel();
+
+ // Clean the old objects after reset is done so that qml will not freak out about null pointers
+ for (int i = 0; i < deleteVector.count(); ++i)
+ deleteVector[i]->deleteLater();
}
int InspectorControlModel::rowCount(const QModelIndex &parent) const
@@ -833,13 +843,20 @@ void InspectorControlModel::refreshTree()
rebuildTree();
} else {
// group structure is intact, let's walk to see which rows changed
+ QVector<QObject *> deleteVector;
long theCount = m_inspectableBase->GetGroupCount();
for (long theIndex = 0; theIndex < theCount; ++theIndex) {
if (isGroupRebuildRequired(m_inspectableBase, theIndex)) {
+ auto group = m_groupElements[theIndex];
+ for (int p = 0; p < group.controlElements.count(); ++p)
+ deleteVector.append(group.controlElements[p].value<QObject *>());
m_groupElements[theIndex] = computeGroup(m_inspectableBase, theIndex);
Q_EMIT dataChanged(index(theIndex), index(theIndex));
}
}
+ // Clean the old objects after refresh is done so that qml will not freak out
+ for (int i = 0; i < deleteVector.count(); ++i)
+ deleteVector[i]->deleteLater();
}
}
diff --git a/src/Authoring/Studio/Palettes/Inspector/InspectorControlModel.h b/src/Authoring/Studio/Palettes/Inspector/InspectorControlModel.h
index 9e0009f2..78f5378b 100644
--- a/src/Authoring/Studio/Palettes/Inspector/InspectorControlModel.h
+++ b/src/Authoring/Studio/Palettes/Inspector/InspectorControlModel.h
@@ -160,8 +160,6 @@ private:
QVariantList controlElements;
~GroupInspectorControl() {
- //for (auto element : controlElements)
- // element.value<QObject *>()->deleteLater();
}
};