SceneGraph: Don't let QSGRenderNode::m_matrix be a dangling pointer

Previously QSGRenderNode::m_matrix would be a dangling pointer most of
the time. We document it as being valid during both the prepare, and
render methods, but it would only be valid during the prepare phase.
This was solved with the projectionMatrix by keeping a local copy
instead of a pointer. No code was actually using the dangling pointer,
but as a preventive measure since we document matrix as being valid also
during the rhiRender we now have a local copy in QSGRenderNodePrivate,
and manually set the pointer reference for the API, as well as a note to
fix this non-ideal situtation in Qt 7.

Fixes: QTBUG-97589
Change-Id: Idc0617de579d3d4ce5cc590534445f609adb9d61
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
This commit is contained in:
Andy Nichols 2023-03-16 14:58:52 +01:00 committed by Andy Nichols
parent 55cb484934
commit 02e9a6b325
3 changed files with 5 additions and 3 deletions

View File

@ -225,8 +225,8 @@ QRegion QSGSoftwareRenderableNode::renderNode(QPainter *painter, bool forceOpaqu
return QRegion();
} else {
QSGRenderNodePrivate *rd = QSGRenderNodePrivate::get(m_handle.renderNode);
QMatrix4x4 m = m_transform;
rd->m_matrix = &m;
rd->m_localMatrix = m_transform;
rd->m_matrix = &rd->m_localMatrix;
rd->m_opacity = m_opacity;
// all the clip region below is in world coordinates, taking m_transform into account already

View File

@ -3933,7 +3933,8 @@ bool Renderer::prepareRhiRenderNode(Batch *batch, PreparedRenderBatch *renderBat
}
xform = xform->parent();
}
rd->m_matrix = &matrix;
rd->m_localMatrix = matrix;
rd->m_matrix = &rd->m_localMatrix;
QSGNode *opacity = e->renderNode->parent();
rd->m_opacity = 1.0;

View File

@ -33,6 +33,7 @@ public:
qreal m_opacity;
QSGRenderTarget m_rt;
QMatrix4x4 m_projectionMatrix;
QMatrix4x4 m_localMatrix; // ### Qt 7 m_matrix should not be a pointer
};
QT_END_NAMESPACE