From 306116dbdeb41052b9606874bc4aa6f41146b0c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Thu, 2 Jun 2022 23:22:34 +0200 Subject: [PATCH] Fixed possible crash on map unload --- src/map/imgmap.cpp | 10 ++++++---- src/map/imgmap.h | 9 +++++++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/map/imgmap.cpp b/src/map/imgmap.cpp index 6ee7844f..9a78d632 100644 --- a/src/map/imgmap.cpp +++ b/src/map/imgmap.cpp @@ -71,6 +71,8 @@ void IMGMap::load() void IMGMap::unload() { + cancelJobs(true); + for (int i = 0; i < _data.size(); i++) _data.at(i)->clear(); } @@ -100,7 +102,7 @@ int IMGMap::zoomFit(const QSize &size, const RectC &rect) int IMGMap::zoomIn() { - cancelJobs(); + cancelJobs(false); _zoom = qMin(_zoom + 1, _data.first()->zooms().max()); updateTransform(); @@ -109,7 +111,7 @@ int IMGMap::zoomIn() int IMGMap::zoomOut() { - cancelJobs(); + cancelJobs(false); _zoom = qMax(_zoom - 1, _data.first()->zooms().min()); updateTransform(); @@ -184,10 +186,10 @@ void IMGMap::jobFinished(IMGMapJob *job) emit tilesLoaded(); } -void IMGMap::cancelJobs() +void IMGMap::cancelJobs(bool wait) { for (int i = 0; i < _jobs.size(); i++) - _jobs.at(i)->cancel(); + _jobs.at(i)->cancel(wait); } void IMGMap::draw(QPainter *painter, const QRectF &rect, Flags flags) diff --git a/src/map/imgmap.h b/src/map/imgmap.h index b5e1b5f7..732bf750 100644 --- a/src/map/imgmap.h +++ b/src/map/imgmap.h @@ -24,7 +24,12 @@ public: _future = QtConcurrent::map(_tiles, &IMG::RasterTile::render); _watcher.setFuture(_future); } - void cancel() {_future.cancel();} + void cancel(bool wait) + { + _future.cancel(); + if (wait) + _future.waitForFinished(); + } const QList &tiles() const {return _tiles;} signals: @@ -85,7 +90,7 @@ private: bool isRunning(const QString &key) const; void runJob(IMGMapJob *job); void removeJob(IMGMapJob *job); - void cancelJobs(); + void cancelJobs(bool wait); QList _data; int _zoom;