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

Fixed broken extended objects segment fetching

This commit is contained in:
Martin Tůma 2020-06-28 19:51:59 +02:00
parent a339706293
commit 473d03cf1f
2 changed files with 34 additions and 23 deletions

View File

@ -122,6 +122,33 @@ bool TREFile::init()
return (_firstLevel >= 0); return (_firstLevel >= 0);
} }
int TREFile::readExtEntry(Handle &hdl, quint32 &polygons, quint32 &lines,
quint32 &points)
{
int rb = 0;
if (_flags & 1) {
if (!readUInt32(hdl, polygons))
return -1;
rb += 4;
} else
polygons = 0;
if (_flags & 2) {
if (!readUInt32(hdl, lines))
return -1;
rb += 4;
} else
lines = 0;
if (_flags & 4) {
if (!readUInt32(hdl, points))
return -1;
rb += 4;
} else
points = 0;
return rb;
}
bool TREFile::load(int idx) bool TREFile::load(int idx)
{ {
Handle hdl(this); Handle hdl(this);
@ -196,25 +223,11 @@ bool TREFile::load(int idx)
if (!seek(hdl, _extended.offset + (skip - diff) * _extended.itemSize)) if (!seek(hdl, _extended.offset + (skip - diff) * _extended.itemSize))
goto error; goto error;
quint32 polygons = 0, lines = 0, points = 0; quint32 polygons, lines, points;
int rb;
for (int i = 0; i < sl.size(); i++) { for (int i = 0; i < sl.size(); i++) {
quint32 rb = 0; if ((rb = readExtEntry(hdl, polygons, lines, points)) < 0)
goto error;
if (_flags & 1) {
if (!readUInt32(hdl, polygons))
goto error;
rb += 4;
}
if (_flags & 2) {
if (!readUInt32(hdl, lines))
goto error;
rb += 4;
}
if (_flags & 4) {
if (!readUInt32(hdl, points))
goto error;
rb += 4;
}
sl.at(i)->setExtOffsets(polygons, lines, points); sl.at(i)->setExtOffsets(polygons, lines, points);
if (i) if (i)
@ -225,8 +238,7 @@ bool TREFile::load(int idx)
} }
if (idx != _levels.size() - 1) { if (idx != _levels.size() - 1) {
if (!(readUInt32(hdl, polygons) && readUInt32(hdl, lines) if (readExtEntry(hdl, polygons, lines, points) < 0)
&& readUInt32(hdl, points)))
goto error; goto error;
sl.last()->setExtEnds(polygons, lines, points); sl.last()->setExtEnds(polygons, lines, points);
} }

View File

@ -46,9 +46,8 @@ private:
bool load(int idx); bool load(int idx);
int level(int bits, bool baseMap); int level(int bits, bool baseMap);
bool parsePoly(Handle hdl, quint32 pos, const QMap<int, int> &level2bits, int readExtEntry(Handle &hdl, quint32 &polygons, quint32 &lines,
QMap<quint32, int> &map); quint32 &points);
bool parsePoints(Handle hdl, quint32 pos, const QMap<int, int> &level2bits);
friend QDebug operator<<(QDebug dbg, const MapLevel &level); friend QDebug operator<<(QDebug dbg, const MapLevel &level);