From 2639281354445f0e37b5dd2e6927155361aaf792 Mon Sep 17 00:00:00 2001 From: "Robert C. Helling" Date: Wed, 16 Mar 2016 00:29:28 +0100 Subject: Copy picture struct for worker thread This copies the picture struct when delegating image handling to a worker thread to prevent a crashe when main thread frees the picture upon selecting a different dive. Signed-off-by: Robert C. Helling Signed-off-by: Dirk Hohndel --- qt-ui/divepicturewidget.cpp | 13 ++++++++++--- qt-ui/divepicturewidget.h | 1 + 2 files changed, 11 insertions(+), 3 deletions(-) (limited to 'qt-ui') diff --git a/qt-ui/divepicturewidget.cpp b/qt-ui/divepicturewidget.cpp index bed3d3bd1..5e3711044 100644 --- a/qt-ui/divepicturewidget.cpp +++ b/qt-ui/divepicturewidget.cpp @@ -23,16 +23,17 @@ void loadPicture(struct picture *picture) SHashedImage::SHashedImage(struct picture *picture) : QImage() { - QUrl url = QUrl::fromUserInput(QString(picture->filename)); + QUrl url = QUrl::fromUserInput(localFilePath(QString(picture->filename))); + if(url.isLocalFile()) load(url.toLocalFile()); if (isNull()) { // Hash lookup. load(fileFromHash(picture->hash)); if (!isNull()) { - QtConcurrent::run(updateHash, picture); + QtConcurrent::run(updateHash, clone_picture(picture)); } else { - QtConcurrent::run(loadPicture, picture); + QtConcurrent::run(loadPicture, clone_picture(picture)); } } else { QByteArray hash = hashFile(url.toLocalFile()); @@ -46,6 +47,11 @@ ImageDownloader::ImageDownloader(struct picture *pic) picture = pic; } +ImageDownloader::~ImageDownloader() +{ + picture_free(picture); +} + void ImageDownloader::load(){ QUrl url = QUrl::fromUserInput(QString(picture->filename)); if (url.isValid()) { @@ -64,6 +70,7 @@ void ImageDownloader::load(){ void ImageDownloader::saveImage(QNetworkReply *reply) { QByteArray imageData = reply->readAll(); + qDebug() << "downloaded "; QImage image = QImage(); image.loadFromData(imageData); if (image.isNull()) diff --git a/qt-ui/divepicturewidget.h b/qt-ui/divepicturewidget.h index 54f5bb826..ff1240ed8 100644 --- a/qt-ui/divepicturewidget.h +++ b/qt-ui/divepicturewidget.h @@ -11,6 +11,7 @@ class ImageDownloader : public QObject { Q_OBJECT; public: ImageDownloader(struct picture *picture); + ~ImageDownloader(); void load(); private: struct picture *picture; -- cgit v1.2.3-70-g09d2