1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-27 21:24:47 +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()
{
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)

View File

@ -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<IMG::RasterTile> &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<IMG::MapData *> _data;
int _zoom;