QGraphicsItem::addToGroup causing crash. A bug ? [solved]



  • Hi!
    So.. There is a part of code:
    @
    if (pEvent->button() == Qt::LeftButton)
    {
    if (!m_pAddingPolygonItemGroup)
    {
    m_pAddingPolygonItemGroup = new QGraphicsItemGroup;
    m_pAddingPolygonItemGroup->setZValue(2.0f);
    addItem(m_pAddingPolygonItemGroup);
    }

            m_addingPolygon.append(screenPos);
            int iPolySize = m_addingPolygon.size();
            if (iPolySize > 1)
            {
                const QPointF& p1 = m_addingPolygon[iPolySize-2];
                const QPointF& p2 = m_addingPolygon[iPolySize-1];
                QGraphicsLineItem* pLineItem = new QGraphicsLineItem(p1.x(), p1.y(), p2.x(), p2.y());
                QPen pen(QColor(255, 255, 255, 200));
                pen.setWidth(1);
                pLineItem->setPen(pen);
                m_pAddingPolygonItemGroup->addToGroup(pLineItem); // <------------ Here is the crash
            }
        }
    

    @

    So this part of code did following: I put a number of lines, clicking by mouse, into the scene using the QGraphicsItemGroup. The first line I put to the group causing crash.

    Additional information about the crash:

    • Last 3 line of the call stack:
      Qt5Widgetsd.dll!QGraphicsItem::itemTransform(const QGraphicsItem * other=0x000000000037e0c0, bool * ok=0x0000000000208b00) Line 4259 C++
      Qt5Widgetsd.dll!QGraphicsItemGroup::addToGroup(QGraphicsItem * item=0x0000000001d96d10) Line 10962 C++
      TerrainEditor_Qt01.exe!MapScene::mousePressEvent(QGraphicsSceneMouseEvent * pEvent=0x0000000000209e00) Line 173 C++

    • The message that is written at the moment of the crash:
      "Unhandled exception at 0x00000000675618FA (Qt5Widgetsd.dll) in TerrainEditor_Qt01.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF."

    • My investigation of the asm code:
      I tried to compare the cpp-code which I had found in internet, but unfortunately it was different sources. So according to asm code the problem is in QGraphicsItem::itemTransform function. Going deep further into the code I found that this should happen beacuse of d_ptr-> calling.. I mean QScopedPointer<QGraphicsItemPrivate,QScopedPointerDeleter<QGraphicsItemPrivate> >::operator->.. However the first calling is good..
      The part of the asm code:
      @
      00000000547218D5 call QScopedPointer<QGraphicsItemPrivate,QScopedPointerDeleter<QGraphicsItemPrivate> >::operator-> (0541BA150h) // returns valid pointer
      00000000547218DA mov rax,qword ptr [rax+80h]
      00000000547218E1 mov qword ptr [parent],rax
      00000000547218E6 mov rax,qword ptr [other]
      00000000547218EE add rax,8
      00000000547218F2 mov rcx,rax
      00000000547218F5 call QScopedPointer<QGraphicsItemPrivate,QScopedPointerDeleter<QGraphicsItemPrivate> >::operator-> (0541BA150h) // returns an invalid pointer
      00000000547218FA mov rax,qword ptr [rax+80h] // <--- crash is here
      0000000054721901 mov qword ptr [otherParent],rax
      0000000054721906 mov rax,qword ptr [other]
      @

    I would be grateful for any help.
    Thank you in advance!



  • Oh.. Shame on me.. I simply do not initialized m_pAddingPolygonItemGroup. This pointer was so real value in debugger that I even didn't check it for being initalized.
    Sorry.


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Glad you found out and thanks for sharing.

    Can you also please update the thread title prepending [solved] so other forum users may know solution has been found :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.