0

I have around 1600+ gif files to run depending on condition. I am using QMovie to play the gif files. I am getting below error in few conditions (random, not every time)

#0  0x00007fb88d74c621 in _int_malloc () at /lib64/libc.so.6
#1  0x00007fb88d74e690 in malloc () at /lib64/libc.so.6
#2  0x00007fb88e53a630 in QByteArray::realloc(int) () at /usr/lib64/libQtCore.so.4
#3  0x00007fb88e53b99d in QByteArray::remove(int, int) () at /usr/lib64/libQtCore.so.4
#4  0x00007fb881527c0c in  () at /usr/lib64/qt4/plugins/imageformats/libqgif.so
#5  0x00007fb881527d10 in  () at /usr/lib64/qt4/plugins/imageformats/libqgif.so
#6  0x00007fb88ec572b6 in  () at /usr/lib64/libQtGui.so.4
#7  0x00007fb88ec5765f in  () at /usr/lib64/libQtGui.so.4
#8  0x00007fb88ec578b7 in  () at /usr/lib64/libQtGui.so.4
#9  0x00007fb88e64e1fa in QMetaObject::activate(QObject*, QMetaObject const*, int, void**) () at /usr/lib64/libQtCore.so.4

As I am unable to reproduce the bug. So I have written a small program which will go into each folder and play gif files. What I have observed is when I play all 1600+ files, while playing 1008th gif file, it stops reading file. I checked the frameCount(), it shows -1. Then I have played 1008th gif file alone, it plays without any error.

I am using VMware WorkStation 12 Pro and QT 5.4.2 (GCC 4.8.3).

Here is the code, which reads files and plays gif file from folders and sub-fodlers.

#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    isMovieFinsihed = true;
    it = new QDirIterator("/home/trainsim/GIF_DATA", QDir::NoFilter, QDirIterator::Subdirectories);
    NextFile();
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::movieFinished()
{
    if (video->currentFrameNumber() == (video->frameCount() - 1))
    {
        isMovieFinsihed = true;
        video->stop();
        //video->deleteLater();
        std::cout << "Movie Finished" << std::endl;
        NextFile();
    }
}

void MainWindow::NextFile()
{
    if(it->hasNext() && isMovieFinsihed)
    {
        isMovieFinsihed = false;
        QFileInfo f(it->next());
        if (f.isFile())
        {
            std::cout << "FileName: " << f.filePath().toStdString() << std::endl;
            video = new QMovie();
            video->setFileName(f.filePath());
            video->start();
            std::cout<< "Loop count: " << video->loopCount() << std::endl;
            ui->label->setMovie(video);
            ui->label->show();
            QObject::connect(video, SIGNAL(frameChanged(int)), this, SLOT(movieFinished()));

            std::cout << "ui->label->movie()->frameCount(): " << ui->label->movie()->frameCount() << std::endl;
        }
        else if (f.isDir())
        {
            isMovieFinsihed = true;
            NextFile();
        }
    }
}

Could you someone tell me where the problem is? Why after 1008th gif, QMovie cannot play. And I also tried to delete the QMOvie object after everytime it finishes playing and created new QMovie. I am not sure if it is right way.

Need Help

  1. Why gif file stops playing?
  2. Is it ok to delete QMovie object after it finish playing

Additional information, When I create QMovie object once and load multiple gif files, then crash occurs. If I create object for every gif file and delete once the gif is finishes playing then it works fine.

Swapna
  • 1
  • 2
  • 1
    can you give us a code example? – Raffallo Jul 01 '19 at 08:24
  • @Swapna: Seems that you are running out of memory. It looks to me, as if you are creating the costy `QMovie` Object more than once.Just create it in the constructor once and make it a member variable. – Aleph0 Jul 01 '19 at 08:52
  • Sorry my bad, I couldn't explain the my problem properly. Initially, I have created one QMovie object and loading multiple gif files. Then the problem occurs. So I have created object for every gif file and deleted once the gif finishes playing then it works well without any issue. – Swapna Jul 01 '19 at 09:36
  • @Swapna: Try to call `deleteLater video` in `movieFinished`. The documentation says that `QMovie`'s purpose is to play animated file formats and not to set each frame separately. That might be also a kind of misconception? – Aleph0 Jul 01 '19 at 12:57
  • Thanks for the reply Aleph0. I still do not understand, QMovie object (created in constructor to load multiple gif files) fails reading from 1008th gif file. Could someone explain why is that? – Swapna Jul 02 '19 at 04:29
  • Could someone please explain below error. #0 0x00007fb88d74c621 in _int_malloc () at /lib64/libc.so.6 #1 0x00007fb88d74e690 in malloc () at /lib64/libc.so.6 #2 0x00007fb88e53a630 in QByteArray::realloc(int) () at /usr/lib64/libQtCore.so.4 #3 0x00007fb88e53b99d in QByteArray::remove(int, int) () at /usr/lib64/libQtCore.so.4 #4 0x00007fb881527c0c in () at /usr/lib64/qt4/plugins/imageformats/libqgif.so #5 0x00007fb881527d10 in () at /usr/lib64/qt4/plugins/imageformats/libqgif.so #6 0x00007fb88ec572b6 in () at /usr/lib64/libQtGui.so.4 – Swapna Jul 02 '19 at 04:32

0 Answers0