Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. updatePaintNode example causing segmentation fault

updatePaintNode example causing segmentation fault

Scheduled Pinned Locked Moved Solved QML and Qt Quick
updatepaintnodesegfaultqmlcustomcomponent
3 Posts 2 Posters 712 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mxyn
    wrote on 27 Jun 2020, 00:45 last edited by
    #1

    Hello, I'm just trying to get familiar with updatePaintNode() by running sample code.

    This code runs fine. I see a red rectangle show up
    from this example

    QSGNode *Zones::updatePaintNode(QSGNode * oldNode, UpdatePaintNodeData *)
    {
    QSGSimpleRectNode *n = static_cast<QSGSimpleRectNode *>(oldNode);
        if(!n) {
            n = new QSGSimpleRectNode();
    	n->setColor(Qt::red);
        }
        //n->setRect(boundingRect());
        n->setRect(0,0,500,500);
        n->setColor(Qt::red);
        return n;
    }
    

    But this code causes a segmentation fault.
    from the bezier example

    QSGNode *Zones::updatePaintNode(QSGNode * oldNode, UpdatePaintNodeData *)
    {
        QSGGeometryNode *root = nullptr;
        QSGGeometry *geometry = nullptr;
    
        if(!oldNode){
            root = new QSGGeometryNode;
            geometry = new QSGGeometry(QSGGeometry::defaultAttributes_Point2D(), 3);
            geometry->setDrawingMode(QSGGeometry::DrawLineLoop);
            geometry->setLineWidth(6);
            root->setFlag(QSGNode::OwnsGeometry);
    
            geometry->vertexDataAsPoint2D()[0].set(0, 0);
        	geometry->vertexDataAsPoint2D()[1].set(0,500);
      	geometry->vertexDataAsPoint2D()[2].set(500,500);
    
    
            QSGFlatColorMaterial *material = new QSGFlatColorMaterial;
            material->setColor(Qt::blue);
            root->setMaterial(material);
            root->setFlag(QSGNode::OwnsMaterial);
        }
        else
        {
            root=static_cast<QSGGeometryNode*>(oldNode);
            geometry = root->geometry();
            geometry->allocate(3);
        }
        root->markDirty(QSGNode::DirtyGeometry);
        qDebug("7");
    
       if(!root)
    	qDebug("no root node");
       else
    	qDebug("valid root node");
        return root;
    }
    

    Here is the qml file that it is related

    import QtQuick 2.0
    import DrawZones 1.0
    
    
    Item {
        anchors.fill: parent
    
        Zones {
            id: zoneOB 
            anchors.fill: parent
            objectName: "zone"
        } //Zone
    }
    
    1 Reply Last reply
    0
    • D Offline
      D Offline
      dheerendra
      Qt Champions 2022
      wrote on 27 Jun 2020, 05:52 last edited by
      #2

      You are missing attach the geometry.

      root->setGeometry(geometry);

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      M 1 Reply Last reply 27 Jun 2020, 06:52
      1
      • D dheerendra
        27 Jun 2020, 05:52

        You are missing attach the geometry.

        root->setGeometry(geometry);

        M Offline
        M Offline
        mxyn
        wrote on 27 Jun 2020, 06:52 last edited by
        #3

        @dheerendra AH! THANK YOU! @_@

        1 Reply Last reply
        0

        3/3

        27 Jun 2020, 06:52

        • Login

        • Login or register to search.
        3 out of 3
        • First post
          3/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved