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
- Why gif file stops playing?
- 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.