summaryrefslogtreecommitdiffstats
path: root/src/render/materialsystem/qtechnique.cpp
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire@kdab.com>2016-05-20 17:11:37 +0200
committerSean Harmer <sean.harmer@kdab.com>2016-05-23 16:31:55 +0000
commit073930f2ef030b3019c323999d910185f4639d9b (patch)
tree0c2bba252f7a92d4f3841fbe42eeca27e2a8a838 /src/render/materialsystem/qtechnique.cpp
parent15dace7c02bc5acdf02f94c8be08fec1a792383c (diff)
Shared node bookkeeping
Any time a property references a QNode there is a risk that the node gets destroyed and then the property is left pointing to a dangling pointer. To handle such cases, setters of such properties are able to use a helper that internally connect QObject::destroyed signal to a setter removal method. Change-Id: I42428c851d0e3d2d88ab0cf6a5b75605334ec648 Task-number: QTBUG-53456 Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src/render/materialsystem/qtechnique.cpp')
-rw-r--r--src/render/materialsystem/qtechnique.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/render/materialsystem/qtechnique.cpp b/src/render/materialsystem/qtechnique.cpp
index f2d146202..c0cc175f9 100644
--- a/src/render/materialsystem/qtechnique.cpp
+++ b/src/render/materialsystem/qtechnique.cpp
@@ -97,6 +97,9 @@ void QTechnique::addFilterKey(QFilterKey *filterKey)
if (!d->m_filterKeys.contains(filterKey)) {
d->m_filterKeys.append(filterKey);
+ // Ensures proper bookkeeping
+ d->registerDestructionHelper(filterKey, &QTechnique::removeFilterKey, d->m_filterKeys);
+
// We need to add it as a child of the current node if it has been declared inline
// Or not previously added as a child of the current node so that
// 1) The backend gets notified about it's creation
@@ -122,6 +125,8 @@ void QTechnique::removeFilterKey(QFilterKey *filterKey)
d->notifyObservers(change);
}
d->m_filterKeys.removeOne(filterKey);
+ // Remove bookkeeping connection
+ d->unregisterDestructionHelper(filterKey);
}
QVector<QFilterKey *> QTechnique::filterKeys() const
@@ -137,6 +142,9 @@ void QTechnique::addParameter(QParameter *parameter)
if (!d->m_parameters.contains(parameter)) {
d->m_parameters.append(parameter);
+ // Ensures proper bookkeeping
+ d->registerDestructionHelper(parameter, &QTechnique::removeParameter, d->m_parameters);
+
// We need to add it as a child of the current node if it has been declared inline
// Or not previously added as a child of the current node so that
// 1) The backend gets notified about it's creation
@@ -162,6 +170,8 @@ void QTechnique::removeParameter(QParameter *parameter)
d->notifyObservers(change);
}
d->m_parameters.removeOne(parameter);
+ // Remove bookkeeping connection
+ d->unregisterDestructionHelper(parameter);
}
/*!
@@ -176,6 +186,9 @@ void QTechnique::addRenderPass(QRenderPass *pass)
if (!d->m_renderPasses.contains(pass)) {
d->m_renderPasses.append(pass);
+ // Ensures proper bookkeeping
+ d->registerDestructionHelper(pass, &QTechnique::removeRenderPass, d->m_renderPasses);
+
// We need to add it as a child of the current node if it has been declared inline
// Or not previously added as a child of the current node so that
// 1) The backend gets notified about it's creation
@@ -206,6 +219,8 @@ void QTechnique::removeRenderPass(QRenderPass *pass)
d->notifyObservers(change);
}
d->m_renderPasses.removeOne(pass);
+ // Remove bookkeeping connection
+ d->unregisterDestructionHelper(pass);
}
/*!