1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-24 03:35:53 +01:00

Fixed possible crash on map unload

This commit is contained in:
Martin Tůma 2022-06-02 23:22:34 +02:00
parent ca1c576562
commit 306116dbde
2 changed files with 13 additions and 6 deletions

View File

@ -71,6 +71,8 @@ void IMGMap::load()
void IMGMap::unload() void IMGMap::unload()
{ {
cancelJobs(true);
for (int i = 0; i < _data.size(); i++) for (int i = 0; i < _data.size(); i++)
_data.at(i)->clear(); _data.at(i)->clear();
} }
@ -100,7 +102,7 @@ int IMGMap::zoomFit(const QSize &size, const RectC &rect)
int IMGMap::zoomIn() int IMGMap::zoomIn()
{ {
cancelJobs(); cancelJobs(false);
_zoom = qMin(_zoom + 1, _data.first()->zooms().max()); _zoom = qMin(_zoom + 1, _data.first()->zooms().max());
updateTransform(); updateTransform();
@ -109,7 +111,7 @@ int IMGMap::zoomIn()
int IMGMap::zoomOut() int IMGMap::zoomOut()
{ {
cancelJobs(); cancelJobs(false);
_zoom = qMax(_zoom - 1, _data.first()->zooms().min()); _zoom = qMax(_zoom - 1, _data.first()->zooms().min());
updateTransform(); updateTransform();
@ -184,10 +186,10 @@ void IMGMap::jobFinished(IMGMapJob *job)
emit tilesLoaded(); emit tilesLoaded();
} }
void IMGMap::cancelJobs() void IMGMap::cancelJobs(bool wait)
{ {
for (int i = 0; i < _jobs.size(); i++) 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) void IMGMap::draw(QPainter *painter, const QRectF &rect, Flags flags)

View File

@ -24,7 +24,12 @@ public:
_future = QtConcurrent::map(_tiles, &IMG::RasterTile::render); _future = QtConcurrent::map(_tiles, &IMG::RasterTile::render);
_watcher.setFuture(_future); _watcher.setFuture(_future);
} }
void cancel() {_future.cancel();} void cancel(bool wait)
{
_future.cancel();
if (wait)
_future.waitForFinished();
}
const QList<IMG::RasterTile> &tiles() const {return _tiles;} const QList<IMG::RasterTile> &tiles() const {return _tiles;}
signals: signals:
@ -85,7 +90,7 @@ private:
bool isRunning(const QString &key) const; bool isRunning(const QString &key) const;
void runJob(IMGMapJob *job); void runJob(IMGMapJob *job);
void removeJob(IMGMapJob *job); void removeJob(IMGMapJob *job);
void cancelJobs(); void cancelJobs(bool wait);
QList<IMG::MapData *> _data; QList<IMG::MapData *> _data;
int _zoom; int _zoom;