From 293ba0db51364e2009a8d1200469cccfe6b13fc7 Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Mon, 30 Mar 2020 10:53:08 +0200 Subject: [PATCH] Don't fail on parse errors in multithreaded mode #746 --- src/ifcgeom/IfcGeomIteratorImplementation.h | 38 +++++++++++++++++---- 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/src/ifcgeom/IfcGeomIteratorImplementation.h b/src/ifcgeom/IfcGeomIteratorImplementation.h index dec994b583..cfa5d5d42a 100644 --- a/src/ifcgeom/IfcGeomIteratorImplementation.h +++ b/src/ifcgeom/IfcGeomIteratorImplementation.h @@ -388,18 +388,24 @@ namespace IfcGeom { void collect() { int i = 0; IfcSchema::IfcProduct::list* previous = nullptr; - while (auto rp = get_next_task()) { + while (auto rp = try_get_next_task()) { // Note that get_next_task() mutates the state of the iterator // we use that capture all products that can be processed as // part of this representation and then keep iterating until // the underlying list of products changes. if (ifcproducts.get() != previous) { previous = ifcproducts.get(); - geometry_conversion_task t; - t.index = i++; - t.representation = *representation_iterator; - t.products = ifcproducts; - tasks_.emplace_back(t); + if (ifcproducts->size()) { + geometry_conversion_task t; + t.index = i++; + t.representation = *representation_iterator; + t.products = ifcproducts; + tasks_.emplace_back(t); + } + } + + if (rp->which() == 1) { + Logger::Error(boost::get(*rp)); } _nextShape(); @@ -599,6 +605,26 @@ namespace IfcGeom { return associated_single_materials.size() == 1; } + boost::optional,IfcParse::IfcException>> try_get_next_task() { + boost::variant< + std::pair, + IfcParse::IfcException + > r; + try { + auto p = get_next_task(); + if (p) { + r = *p; + } else { + return boost::none; + } + } catch (IfcParse::IfcException& e) { + r = e; + } catch (...) { + r = IfcParse::IfcException("Unknown error"); + } + return r; + } + boost::optional> get_next_task() { for (;;) { IfcSchema::IfcRepresentation* representation;