mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
2368f3371b
commit
2639281354
5 changed files with 36 additions and 8 deletions
|
|
@ -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())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue