Details
-
Bug
-
Resolution: Done
-
P2: Important
-
None
-
5.9.4, 5.10.1, 5.11.0
-
None
-
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:
- Start an animated image
- Connect to its frameChanged
- When the frameChanged happens, change the source of the AnimatedImage
- 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 |
224931,3 | Fix crash when changing the source of AnimatedImage after a frame change | 5.11 | qt/qtdeclarative | Status: MERGED | +2 | 0 |