Skip to content

Commit 92c66c2

Browse files
committed
Catch unparsable point coordinates
1 parent 66f2a4f commit 92c66c2

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

azul.xcodeproj/project.pbxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,7 @@
463463
PRODUCT_NAME = "$(TARGET_NAME)";
464464
SDKROOT = macosx;
465465
SWIFT_OBJC_BRIDGING_HEADER = "src/Azul-Bridging-Header.h";
466+
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
466467
SWIFT_VERSION = 3.0;
467468
};
468469
name = Release;

src/CityGMLParser.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ void CityGMLParser::parse(const char *filePath) {
4545
pugi::xml_document doc;
4646
doc.load_file(filePath);
4747

48+
std::cout << "Loaded XML file" << std::endl;
49+
4850
// With single traversal
4951
ObjectsWalker objectsWalker;
5052
doc.traverse(objectsWalker);

src/CityGMLParser.hpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,18 @@ struct PointsWalker: pugi::xml_tree_walker {
7575
iss >> substring;
7676
if (substring.length() > 0) {
7777
if (currentCoordinate == 0) points.push_back(CityGMLPoint());
78-
points.back().coordinates[currentCoordinate] = std::stof(substring);
79-
currentCoordinate = (currentCoordinate+1)%3;
78+
try {
79+
points.back().coordinates[currentCoordinate] = std::stof(substring);
80+
} catch (const std::invalid_argument& ia) {
81+
std::cout << "Invalid point: " << substring << ". Skipping..." << std::endl;
82+
points.clear();
83+
return true;
84+
} currentCoordinate = (currentCoordinate+1)%3;
8085
}
8186
} while (iss);
8287
if (currentCoordinate != 0) {
8388
std::cout << "Wrong number of coordinates: not divisible by 3" << std::endl;
84-
points.pop_back();
89+
points.clear();
8590
} //std::cout << "Created " << points.size() << " points" << std::endl;
8691
} return true;
8792
}

0 commit comments

Comments
 (0)