aboutsummaryrefslogtreecommitdiffstats
path: root/qt-ui/divepicturewidget.cpp
diff options
context:
space:
mode:
authorGravatar Robert C. Helling <helling@atdotde.de>2016-03-16 00:29:28 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2016-03-15 22:38:47 -0700
commit2639281354445f0e37b5dd2e6927155361aaf792 (patch)
treee7f32a03449941d9789d669760d4b327eeb99ad7 /qt-ui/divepicturewidget.cpp
parent2368f3371bbdb587888d5f04095623c7b8b2ac2e (diff)
downloadsubsurface-2639281354445f0e37b5dd2e6927155361aaf792.tar.gz
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 <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/divepicturewidget.cpp')
-rw-r--r--qt-ui/divepicturewidget.cpp13
1 files changed, 10 insertions, 3 deletions
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())