Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-67427

QML AnimatedImage: crash when changing the image after a frame change

    XMLWordPrintable

Details

    • a609554c031fd57d9a2a3905f5a02cc6b4aa19e9

    Description

      Hello,

      I encountered recently some weird crashes in the application that I'm developing, not 100% reproducible but that happen on precise actions.

      My researches allowed me to isolate the following scenario:

      1. Start an animated image
      2. Connect to its frameChanged
      3. When the frameChanged happens, change the source of the AnimatedImage
      4. Valgrind will yell and the application will most of the time crash.

      The reason is the code of QMovie that emits the frameChanged:

              emit q->updated(frameRect);
              emit q->frameChanged(currentFrameNumber);
      
              if (movieState == QMovie::Running)
                  nextImageTimer.start(nextDelay);
      

      Combined to the code of QQuickAnimatedImage:

      void QQuickAnimatedImage::setSource(const QUrl &url)
      {
          // ...
      
          if (d->_movie) {
              delete d->_movie;
              d->_movie = 0;
          }
      

      So when we listen to frameChanged in QML, and change the source, it will destroy the QMovie, but QMovie will execute after two more lines to start the timer for its next frame:

              if (movieState == QMovie::Running)
                  nextImageTimer.start(nextDelay);
      

      This is the cause of the crash.

      You can also reproduce it with a more "isolated" code that simulates what AnimatedImage does:

      class A : public QObject
      {
          Q_OBJECT
      
      public:
          A()
          {
              _movie = new QMovie(":/cursor_select.gif");
              connect(_movie, SIGNAL(frameChanged(int)), this, SLOT(destroyMovie()));
              _movie->start();
          }
      
      public slots:
          void destroyMovie()
          {
              qDebug() << "Destroying";
              delete _movie;
              _movie = nullptr;
          }
      
      private:
          QMovie *_movie = nullptr;
      };
      

      I don't know how to fix it or if we have to fix it/document it. Do you have any suggestion?

      Best regards,
      Louis

      Attachments

        For Gerrit Dashboard: QTBUG-67427
        # Subject Branch Project Status CR V

        Activity

          People

            srutledg Shawn Rutledge
            amnell Louis du Verdier
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes