Segfault In ~QGraphicsItem() Due To Duplicate Transforms



  • I think the following causes (or can cause) a core:

    @
    QList<QGraphicsTransform*> transforms;
    QGraphicsRotation* rot = new QGraphicsRotation();
    transforms.append(rot);
    transforms.append(rot);
    graphicsitem->setTransformations(transforms);
    @

    I am guessing that ~QGraphicsItem() does this and double frees:
    @
    QList<QGraphicsTransform*> transforms = this->transformations();
    foreach ( QGraphicsTransform* transform, transforms ) {
    delete transform;
    }
    @

    Please delete this if it's stupid.


  • Moderators

    It looks as if you are correct.
    However, in my opinion this is not bug in the lib. You are handling the lib wrong. I cannot imagine a reason why you would define exactly the same transformation twice.

    See the example:
    @
    QList<QGraphicsTransform*> transforms;
    QGraphicsRotation* rot = new QGraphicsRotation();
    rot->setAngle ( 10 );
    transforms.append(rot);
    rot->setAngle ( 100 );
    transforms.append(rot);
    graphicsitem->setTransformations(transforms);
    @
    One could try to rotate by 10 and by 100 degrees, but it will rotate by 200 degrees. So it may happen of course, but it is an flaw in the design.



  • I had some dummy identity transforms in the QGraphicsItem's transform list that had the same address. Anyhow, I changed my code.


  • Moderators

    Completely understood. Unfortunately, these are the cases when you have to look for the origin of the problem a bit longer :-(



  • You're correct in regard with the QGraphicsItemDestructor.

    src/gui/graphicsview/qgraphicsitem.cpp - line 1489ff:

    @
    if (d_ptr->transformData) {
    for(int i = 0; i < d_ptr->transformData->graphicsTransforms.size(); ++i) {
    QGraphicsTransform *t = d_ptr->transformData->graphicsTransforms.at(i);
    static_cast<QGraphicsTransformPrivate *>(t->d_ptr.data())->item = 0;
    delete t;
    }
    }
    @

    So yes, you run into double deletion of a pointer.


Log in to reply
 

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