Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Segfault In ~QGraphicsItem() Due To Duplicate Transforms
Qt 6.11 is out! See what's new in the release blog

Segfault In ~QGraphicsItem() Due To Duplicate Transforms

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 2.9k Views 1 Watching
  • 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.
  • T Offline
    T Offline
    texas
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      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.

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      0
      • T Offline
        T Offline
        texas
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • K Offline
          K Offline
          koahnig
          wrote on last edited by
          #4

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

          Vote the answer(s) that helped you to solve your issue(s)

          1 Reply Last reply
          0
          • G Offline
            G Offline
            goetz
            wrote on last edited by
            #5

            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.

            http://www.catb.org/~esr/faqs/smart-questions.html

            1 Reply Last reply
            0

            • Login

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