From c26a65c56561bff50a402c1120d7961bb7e6b4c3 Mon Sep 17 00:00:00 2001 From: Jeremy Hu Date: Fri, 10 Apr 2020 23:13:56 +0930 Subject: [PATCH] Fix CGAL crash [skip ci] --- src/meshcombiner.cpp | 12 ++++++++++++ src/meshcombiner.h | 1 + 2 files changed, 13 insertions(+) diff --git a/src/meshcombiner.cpp b/src/meshcombiner.cpp index 96f6c992..2cd98d6f 100644 --- a/src/meshcombiner.cpp +++ b/src/meshcombiner.cpp @@ -73,9 +73,18 @@ bool MeshCombiner::Mesh::isSelfIntersected() const return m_isSelfIntersected; } +void MeshCombiner::Mesh::markAsSelfIntersected() +{ + m_isSelfIntersected = true; +} + MeshCombiner::Mesh *MeshCombiner::combine(const Mesh &firstMesh, const Mesh &secondMesh, Method method, std::vector> *combinedVerticesComeFrom) { + if (firstMesh.isNull() || firstMesh.isSelfIntersected() || + secondMesh.isNull() || secondMesh.isSelfIntersected()) + return nullptr; + CgalMesh *resultCgalMesh = nullptr; CgalMesh *firstCgalMesh = (CgalMesh *)firstMesh.m_privateData; CgalMesh *secondCgalMesh = (CgalMesh *)secondMesh.m_privateData; @@ -147,6 +156,9 @@ MeshCombiner::Mesh *MeshCombiner::combine(const Mesh &firstMesh, const Mesh &sec Mesh *mesh = new Mesh; mesh->m_privateData = resultCgalMesh; + if (CGAL::Polygon_mesh_processing::does_self_intersect(*resultCgalMesh)) { + mesh->markAsSelfIntersected(); + } return mesh; } diff --git a/src/meshcombiner.h b/src/meshcombiner.h index 639919e5..22018e96 100644 --- a/src/meshcombiner.h +++ b/src/meshcombiner.h @@ -29,6 +29,7 @@ public: void fetch(std::vector &vertices, std::vector> &faces) const; bool isNull() const; bool isSelfIntersected() const; + void markAsSelfIntersected(); friend MeshCombiner;