summaryrefslogtreecommitdiffstats
path: root/src/render/materialsystem/qmaterial.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/qmaterial.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/qmaterial.cpp')
-rw-r--r--src/render/materialsystem/qmaterial.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/render/materialsystem/qmaterial.cpp b/src/render/materialsystem/qmaterial.cpp
index 644c11b4d..fa4955017 100644
--- a/src/render/materialsystem/qmaterial.cpp
+++ b/src/render/materialsystem/qmaterial.cpp
@@ -112,6 +112,9 @@ void QMaterial::setEffect(QEffect *effect)
Q_D(QMaterial);
if (effect != d->m_effect) {
+ if (d->m_effect)
+ d->unregisterDestructionHelper(d->m_effect);
+
// 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
@@ -119,6 +122,11 @@ void QMaterial::setEffect(QEffect *effect)
if (effect && !effect->parent())
effect->setParent(this);
d->m_effect = effect;
+
+ // Ensures proper bookkeeping
+ if (d->m_effect)
+ d->registerDestructionHelper(d->m_effect, &QMaterial::setEffect, d->m_effect);
+
emit effectChanged(effect);
}
}
@@ -139,6 +147,9 @@ void QMaterial::addParameter(QParameter *parameter)
if (!d->m_parameters.contains(parameter)) {
d->m_parameters.append(parameter);
+ // Ensures proper bookkeeping
+ d->registerDestructionHelper(parameter, &QMaterial::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