我有一个QQuickItem
,它显示用于文本编辑器的文本光标,起初我只有一个光标(QSGGeometry
),放在QOpacityNode
中。当我增加游标的数量时,新的游标会放置在不透明度节点中,但是对QSGNode.appendChildNode()
的调用会产生 分段错误 。
QSGNode * CursorsArea::updatePaintNode(QSGNode *, QQuickItem::UpdatePaintNodeData *){
if (node == nullptr) {
node = new QSGOpacityNode;
}
if (!alpha.update()) {
if (alpha.currentAlpha >= 1.0) {
alpha.setCurrentAlpha(0.0);
}
else {
alpha.setCurrentAlpha(1.0);
}
}
if (editor == nullptr) {
return node;
}
if (node->childCount() != editor->selectionsCount()) {
if (node->childCount() < editor->selectionsCount()) {
for (int i = node->childCount(); i < editor->selectionsCount();
i++) {
auto * geometryNode = new QSGGeometryNode;
auto * geometry =
new QSGGeometry{QSGGeometry::defaultAttributes_Point2D(), 2};
geometry->setLineWidth(m_cursorW);
geometry->setDrawingMode(QSGGeometry::DrawLines);
geometryNode->setGeometry(geometry);
geometryNode->setFlag(QSGNode::OwnsGeometry);
node->appendChildNode(geometryNode); // Segmentation fault here
}
}
else {
while (editor->selectionsCount() < node->childCount()) {
node->removeChildNode(node->firstChild());
}
}
}
}
堆栈跟踪:
1 QSGBatchRenderer :: Renderer :: nodeWawego(QSGNode *, QSGBatchRenderer ::节点*)0x7ffff1248245 2 QSGBatchRenderer :: Renderer :: nodeChanged(QSGNode *, QFlags)0x7ffff124b592 3 QSGRootNode :: notifyNodeChange(QSGNode *, QFlags)
0x7ffff1235b18 4 QSGNode :: markDirty(QFlags) 0x7ffff1235b99 5 icL :: editor :: CursorsArea :: updatePaintNode
cursorsarea.cpp 91 0x7fffd1124939 6 QQuickWindowPrivate :: updateDirtyNode(QQuickItem *)
0x7ffff12d7320 7 QQuickWindowPrivate :: updateDirtyNodes()
0x7ffff12d7794 8 QQuickWindowPrivate :: syncSceneGraph()
0x7ffff12d8cc7 9 ??
0x7ffff12665b3 10 QQuickWindow :: event(QEvent *)
0x7ffff12e3b06 11 QApplicationPrivate :: notify_helper(QObject *, QEvent *)0x7ffff7ac0e14 12 QApplication :: notify(QObject *,QEvent *)
0x7ffff7ac86e1 13 QCoreApplication :: notifyInternal2(QObject *, QEvent *)
0x7ffff020ec39 14 QWindowPrivate :: deliverUpdateRequest()
0x7ffff0c65853 15 QWindow :: event(QEvent *)
0x7ffff0c65d8b 16 QQuickWindow :: event(QEvent *)
0x7ffff12e3a5c 17 QApplicationPrivate :: notify_helper(QObject *, QEvent *)0x7ffff7ac0e14 18 QApplication :: notify(QObject *,QEvent *)
0x7ffff7ac86e1 19 QCoreApplication :: notifyInternal2(QObject *, QEvent *)
0x7ffff020ec39 20 QTimerInfoList :: activateTimers()
0x7ffff026139a 21 ??
0x7ffff0261c5a 22 g_main_context_dispatch
0x7fffef92d3cf 23 ??
0x7fffef92ef89 24 g_main_context_iteration
0x7fffef92efce 25 QEventDispatcherGlib :: processEvents(QFlags) 0x7ffff0261fc9 26 ??
0x7fffe1e18e12 27 QEventLoop :: exec(QFlags)
0x7ffff020d8cc 28 QCoreApplication :: exec()
0x7ffff0215bc6 29 main
main.cpp
我该如何解决?