1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2025-01-19 04:02:09 +01:00

Improved error handling

This commit is contained in:
Martin Tůma 2019-07-18 00:26:27 +02:00
parent d07b6c6a9d
commit 70b5371a6e

View File

@ -113,6 +113,12 @@ bool TREFile::init()
bool TREFile::load(int idx) bool TREFile::load(int idx)
{ {
Handle hdl; Handle hdl;
QList<SubDiv*> sl;
SubDiv *s = 0;
SubDivTree *tree = new SubDivTree();
_subdivs.insert(_levels.at(idx).bits, tree);
quint32 skip = 0; quint32 skip = 0;
for (int i = 0; i < idx; i++) for (int i = 0; i < idx; i++)
@ -121,10 +127,6 @@ bool TREFile::load(int idx)
if (!seek(hdl, _subdivOffset + skip * 16)) if (!seek(hdl, _subdivOffset + skip * 16))
return false; return false;
_subdivs.insert(_levels.at(idx).bits, new SubDivTree());
QList<SubDiv*> sl;
SubDiv *s = 0;
for (int j = 0; j < _levels.at(idx).subdivs; j++) { for (int j = 0; j < _levels.at(idx).subdivs; j++) {
quint32 offset; quint32 offset;
qint32 lon, lat; qint32 lon, lat;
@ -134,10 +136,10 @@ bool TREFile::load(int idx)
if (!(readUInt24(hdl, offset) && readByte(hdl, objects) if (!(readUInt24(hdl, offset) && readByte(hdl, objects)
&& readInt24(hdl, lon) && readInt24(hdl, lat) && readInt24(hdl, lon) && readInt24(hdl, lat)
&& readUInt16(hdl, width) && readUInt16(hdl, height))) && readUInt16(hdl, width) && readUInt16(hdl, height)))
return false; goto error;
if (idx != _levels.size() - 1) if (idx != _levels.size() - 1)
if (!readUInt16(hdl, nextLevel)) if (!readUInt16(hdl, nextLevel))
return false; goto error;
if (s) if (s)
s->setEnd(offset); s->setEnd(offset);
@ -158,13 +160,14 @@ bool TREFile::load(int idx)
min[1] = bounds.bottom(); min[1] = bounds.bottom();
max[0] = bounds.right(); max[0] = bounds.right();
max[1] = bounds.top(); max[1] = bounds.top();
_subdivs[_levels.at(idx).bits]->Insert(min, max, s);
tree->Insert(min, max, s);
} }
if (idx != _levels.size() - 1) { if (idx != _levels.size() - 1) {
quint32 offset; quint32 offset;
if (!readUInt24(hdl, offset)) if (!readUInt24(hdl, offset))
return false; goto error;
s->setEnd(offset); s->setEnd(offset);
} }
@ -182,30 +185,36 @@ bool TREFile::load(int idx)
quint32 polygons, lines, points; quint32 polygons, lines, points;
if (!seek(hdl, _extended.offset + (skip - diff) * _extended.itemSize)) if (!seek(hdl, _extended.offset + (skip - diff) * _extended.itemSize))
return false; goto error;
for (int i = 0; i < sl.size(); i++) { for (int i = 0; i < sl.size(); i++) {
if (!(readUInt32(hdl, polygons) && readUInt32(hdl, lines) if (!(readUInt32(hdl, polygons) && readUInt32(hdl, lines)
&& readUInt32(hdl, points))) && readUInt32(hdl, points)))
return false; goto error;
sl.at(i)->setExtOffsets(polygons, lines, points); sl.at(i)->setExtOffsets(polygons, lines, points);
if (i) if (i)
sl.at(i-1)->setExtEnds(polygons, lines, points); sl.at(i-1)->setExtEnds(polygons, lines, points);
if (!seek(hdl, hdl.pos + _extended.itemSize - 12)) if (!seek(hdl, hdl.pos + _extended.itemSize - 12))
return false; goto error;
} }
if (idx != _levels.size() - 1) { if (idx != _levels.size() - 1) {
if (!(readUInt32(hdl, polygons) && readUInt32(hdl, lines) if (!(readUInt32(hdl, polygons) && readUInt32(hdl, lines)
&& readUInt32(hdl, points))) && readUInt32(hdl, points)))
return false; goto error;
sl.last()->setExtEnds(polygons, lines, points); sl.last()->setExtEnds(polygons, lines, points);
} }
} }
return true; return true;
error:
qDeleteAll(sl);
tree->RemoveAll();
return false;
} }
void TREFile::clear() void TREFile::clear()