From f61d9fcd5567d676a98451a94db7d2ca9b6cadff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Sun, 19 Jan 2020 17:40:14 +0100 Subject: [PATCH] Fixed crash on error introduced with the latest error handling changes (+ ignore broken tiles rather than terminate parsing) --- src/map/IMG/img.cpp | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/src/map/IMG/img.cpp b/src/map/IMG/img.cpp index 3dcc20a2..af7d1e32 100644 --- a/src/map/IMG/img.cpp +++ b/src/map/IMG/img.cpp @@ -7,6 +7,8 @@ #define CACHE_SIZE 8388608 /* 8MB */ +typedef QMap TileMap; + struct CTX { CTX(const RectC &rect, int bits, QList *polygons, @@ -49,7 +51,7 @@ IMG::IMG(const QString &fileName) return; \ } - QMap tileMap; + TileMap tileMap; QString typFile; if (!_file.open(QFile::ReadOnly)) { @@ -78,6 +80,7 @@ IMG::IMG(const QString &fileName) _blockSize = 1 << (e1 + e2); _blockCache.setMaxCost(CACHE_SIZE / _blockSize); + // Read the FAT table quint8 flag; quint64 offset = 0x200; @@ -149,21 +152,30 @@ IMG::IMG(const QString &fileName) } // Create tile tree - for (QMap::iterator it = tileMap.begin(); - it != tileMap.end(); ++it) { - CHECK((*it)->init()); + for (TileMap::iterator it = tileMap.begin(); it != tileMap.end(); ++it) { + VectorTile *tile = it.value(); + + if (!tile->init()) { + qWarning("%s: %s: Invalid map tile", qPrintable(_file.fileName()), + qPrintable(it.key())); + delete tile; + continue; + } double min[2], max[2]; - min[0] = (*it)->bounds().left(); - min[1] = (*it)->bounds().bottom(); - max[0] = (*it)->bounds().right(); - max[1] = (*it)->bounds().top(); - _tileTree.Insert(min, max, *it); + min[0] = tile->bounds().left(); + min[1] = tile->bounds().bottom(); + max[0] = tile->bounds().right(); + max[1] = tile->bounds().top(); + _tileTree.Insert(min, max, tile); - _bounds |= (*it)->bounds(); + _bounds |= tile->bounds(); } - _valid = true; + if (!_tileTree.Count()) + _errorString = "No usable map tile found"; + else + _valid = true; } IMG::~IMG()