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 --- qthelper.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'qthelper.cpp') diff --git a/qthelper.cpp b/qthelper.cpp index 67ce5daff..745fc5f60 100644 --- a/qthelper.cpp +++ b/qthelper.cpp @@ -1182,9 +1182,11 @@ void learnHash(struct picture *picture, QByteArray hash) QString localFilePath(const QString originalFilename) { - if (hashOf.contains(originalFilename) && localFilenameOf.contains(hashOf[originalFilename])) - return localFilenameOf[hashOf[originalFilename]]; - else + if (hashOf.contains(originalFilename)) + if (localFilenameOf.contains(hashOf[originalFilename])) + if (localFilenameOf[hashOf[originalFilename]] != "") + return localFilenameOf[hashOf[originalFilename]]; + return originalFilename; } @@ -1200,6 +1202,7 @@ void updateHash(struct picture *picture) { char *old = picture->hash; picture->hash = strdup(hash.toHex()); free(old); + picture_free(picture); } void hashPicture(struct picture *picture) @@ -1209,13 +1212,14 @@ void hashPicture(struct picture *picture) if (!same_string(picture->hash, "") && !same_string(picture->hash, oldHash)) mark_divelist_changed((true)); free(oldHash); + picture_free(picture); } extern "C" void cache_picture(struct picture *picture) { QString filename = picture->filename; if (!hashOf.contains(filename)) - QtConcurrent::run(hashPicture, picture); + QtConcurrent::run(hashPicture, clone_picture(picture)); } void learnImages(const QDir dir, int max_recursions, bool recursed) -- cgit v1.2.3-70-g09d2