From ea514e9528afb724e911cbf14b8a3be96d7078f7 Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Tue, 25 Oct 2016 10:11:14 +0200 Subject: [PATCH] Fix #148 catch errors when computing model bounding box from product placements. --- src/ifcgeom/IfcGeomIterator.h | 27 +++++++++++++++++---------- src/ifcgeom/IfcRegisterConvertShape.h | 2 +- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/ifcgeom/IfcGeomIterator.h b/src/ifcgeom/IfcGeomIterator.h index 679ea8ed47..90e65cd1c5 100644 --- a/src/ifcgeom/IfcGeomIterator.h +++ b/src/ifcgeom/IfcGeomIterator.h @@ -284,16 +284,23 @@ namespace IfcGeom { for (IfcSchema::IfcProduct::list::it iter = products->begin(); iter != products->end(); ++iter) { IfcSchema::IfcProduct* product = *iter; if (product->hasObjectPlacement()) { - gp_Trsf trsf; // Use a fresh trsf every time in order to prevent the result to be concatenated - if (kernel.convert(product->ObjectPlacement(), trsf)) { - const gp_XYZ& pos = trsf.TranslationPart(); - bounds_min_.SetX(std::min(bounds_min_.X(), pos.X())); - bounds_min_.SetY(std::min(bounds_min_.Y(), pos.Y())); - bounds_min_.SetZ(std::min(bounds_min_.Z(), pos.Z())); - bounds_max_.SetX(std::max(bounds_max_.X(), pos.X())); - bounds_max_.SetY(std::max(bounds_max_.Y(), pos.Y())); - bounds_max_.SetZ(std::max(bounds_max_.Z(), pos.Z())); - } + // Use a fresh trsf every time in order to prevent the result to be concatenated + gp_Trsf trsf; + bool success = false; + try { + success = kernel.convert(product->ObjectPlacement(), trsf); + } catch (...) {} + if (!success) { + continue; + } + + const gp_XYZ& pos = trsf.TranslationPart(); + bounds_min_.SetX(std::min(bounds_min_.X(), pos.X())); + bounds_min_.SetY(std::min(bounds_min_.Y(), pos.Y())); + bounds_min_.SetZ(std::min(bounds_min_.Z(), pos.Z())); + bounds_max_.SetX(std::max(bounds_max_.X(), pos.X())); + bounds_max_.SetY(std::max(bounds_max_.Y(), pos.Y())); + bounds_max_.SetZ(std::max(bounds_max_.Z(), pos.Z())); } } diff --git a/src/ifcgeom/IfcRegisterConvertShape.h b/src/ifcgeom/IfcRegisterConvertShape.h index 911132e8bc..81a2703ee0 100644 --- a/src/ifcgeom/IfcRegisterConvertShape.h +++ b/src/ifcgeom/IfcRegisterConvertShape.h @@ -10,7 +10,7 @@ Logger::Message(Logger::LOG_ERROR, std::string(e.what()) + "\nFailed to convert:", l->entity); \ return false; \ } catch (const Standard_Failure& f) { \ - if (f.GetMessageString()) \ + if (f.GetMessageString() && strlen(f.GetMessageString())) \ Logger::Message(Logger::LOG_ERROR, std::string("Error in: ") + f.GetMessageString() + "\nFailed to convert:", l->entity); \ else \ Logger::Message(Logger::LOG_ERROR, "Failed to convert:", l->entity); \