I use QSGGeometry
, QSGVertexColorMaterial
and a QSGGeometryNode
to draw something real time on my QQuickItem
derived class, which is MyQuickItem
here.
Below is my method updatePaintNode
, where the essence of the redraw logic lies.
QSGNode * MyQuickItem::updatePaintNode(QSGNode * oldNode, UpdatePaintNodeData * updatePaintNodeData) {
if (!oldNode) {
oldNode = new QSGNode;
}
oldNode->removeAllChildNodes();
QSGGeometry * geometry = GetMyGeometry();
QSGVertexColorMaterial * material = new QSGVertexColorMaterial;
QSGGeometryNode * child_node = new QSGGeometryNode;
child_node->setGeometry(geometry);
child_node->setMaterial(material);
child_node->setFlag(QSGNode::OwnsMaterial);
oldNode->appendChildNode(child_node);
return oldNode;
}
Question: The
above logic works great . No functionality issues at all. No performance issues. But I'm worried that I'm causing a memory leak . Take a look at the next two lines in the above method updatePaintNode
, where I highlight raw pointers.
QSGVertexColorMaterial * material = new QSGVertexColorMaterial;
QSGGeometryNode * child_node = new QSGGeometryNode;
, . , , , updatePaintNode
. .
:
, 2 material
child_node
?
child_node->setFlag(QSGNode::OwnsMaterial)
, , QtSceneGraph ?
:
oldNode->removeAllChildNodes()
, . , ?
PS:
: . , . material
child_node
, :
auto material = std::make_shared<QSGVertexColorMaterial>();
auto child_node = new std::make_shared<QSGGeometryNode>();
, material
child_node
.