Skip to content

Commit a80daf2

Browse files
dl3sdolpechacek
andcommitted
OcdFileImport: Handle emtpy area holes
There are .ocd files that erroneously contain an empty area hole, i.e., there are two subsequent points with the Ocd::OcdPoint32::FlagHole property. If such a malformed .ocd file is imported Mapper will crash if the area object containing the empty hole is selected. To fix this, the first of these .ocd points needs to be ignored. Since setPointFlags() applies the HolePoint property to the last point instead of the first point of the next part, the consequence is that instead of removing the first point of these two .ocd points, the second point of the two Mapper points with the HolePoint property needs to be removed. Using a loop ensures that multiple subsequent empty area holes are removed. Co-authored-by: lpechacek <[email protected]>
1 parent 954954e commit a80daf2

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/fileformats/ocd_file_import.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013-2022 Kai Pastor
2+
* Copyright 2013-2023 Kai Pastor
33
*
44
* Some parts taken from file_format_oc*d8{.h,_p.h,cpp} which are
55
* Copyright 2012 Pete Curtis
@@ -2153,6 +2153,17 @@ void OcdFileImport::fillPathCoords(OcdImportedPathObject *object, bool is_area,
21532153
size_t start = 0;
21542154
for (size_t i = 0; i < object->coords.size(); ++i)
21552155
{
2156+
// There are .ocd files that erroneously contain an empty area hole, i.e., there are two subsequent points
2157+
// with the Ocd::OcdPoint32::FlagHole property. To fix this, the first of these points needs to be ignored.
2158+
// Since setPointFlags() applies the HolePoint property to the last point instead of the first point of the next part,
2159+
// the consequence is that instead of removing the first point of these two .ocd points,
2160+
// the second point of the two Mapper points with the HolePoint property needs to be removed.
2161+
// Using a loop ensures that multiple subsequent empty area holes are removed.
2162+
while (is_area && i < object->coords.size() - 1 && object->coords[i].isHolePoint() && object->coords[i+1].isHolePoint())
2163+
{
2164+
object->coords.erase(begin(object->coords) + i + 1);
2165+
}
2166+
21562167
if (!object->coords[i].isHolePoint() && i < object->coords.size() - 1)
21572168
continue;
21582169

0 commit comments

Comments
 (0)