Browse Source

fix crash when meshing certain models

David Rose 21 years ago
parent
commit
95f8fa1fb8

+ 53 - 14
panda/src/builder/mesherFanMaker.I

@@ -24,9 +24,62 @@
 
 #include <math.h>
 
+////////////////////////////////////////////////////////////////////
+//     Function: MesherFanMaker::Constructor
+//       Access: Public
+//  Description: 
+////////////////////////////////////////////////////////////////////
+template <class PrimType>
+MesherFanMaker<PrimType>::
+MesherFanMaker(const Vertex *vertex, Strip *tri, Mesher *mesher) {
+  _vertex = vertex;
+  const Edge *edge = tri->find_opposite_edge(vertex);
+  if (edge != (const Edge *)NULL) {
+    _edges.push_back(edge);
+  }
+  _strips.push_back(tri);
+  _planar = tri->_planar;
+  _mesher = mesher;
+  _bucket = _mesher->_bucket;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: MesherFanMaker::Copy Constructor
+//       Access: Public
+//  Description: 
+////////////////////////////////////////////////////////////////////
+template <class PrimType>
+MesherFanMaker<PrimType>::
+MesherFanMaker(const MesherFanMaker<PrimType> &copy) :
+  _vertex(copy._vertex),
+  _edges(copy._edges),
+  _strips(copy._strips),
+  _planar(copy._planar),
+  _bucket(copy._bucket),
+  _mesher(copy._mesher)
+{
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: MesherFanMaker::Copy Assignment Operator
+//       Access: Public
+//  Description: 
+////////////////////////////////////////////////////////////////////
+template <class PrimType>
+void MesherFanMaker<PrimType>::
+operator = (const MesherFanMaker<PrimType> &copy) {
+  _vertex = copy._vertex;
+  _edges = copy._edges;
+  _strips = copy._strips;
+  _planar = copy._planar;
+  _bucket = copy._bucket;
+  _mesher = copy._mesher;
+}
+
 template <class PrimType>
 INLINE bool MesherFanMaker<PrimType>::
 operator < (const MesherFanMaker &other) const {
+  nassertr(!_edges.empty() && !other._edges.empty(), false);
   return _edges.front() < other._edges.front();
 }
 
@@ -68,20 +121,6 @@ is_coplanar_with(const MesherFanMaker &other) const {
                                     _bucket->_coplanar_threshold);
 }
 
-template <class PrimType>
-MesherFanMaker<PrimType>::
-MesherFanMaker(const Vertex *vertex, Strip *tri, Mesher *mesher) {
-  _vertex = vertex;
-  const Edge *edge = tri->find_opposite_edge(vertex);
-  if (edge != (const Edge *)NULL) {
-    _edges.push_back(edge);
-  }
-  _strips.push_back(tri);
-  _planar = tri->_planar;
-  _mesher = mesher;
-  _bucket = _mesher->_bucket;
-}
-
 template <class PrimType>
 bool MesherFanMaker<PrimType>::
 join(MesherFanMaker &other) {

+ 2 - 0
panda/src/builder/mesherFanMaker.h

@@ -52,6 +52,8 @@ public:
 
   MesherFanMaker() {}
   MesherFanMaker(const Vertex *vertex, Strip *tri, Mesher *mesher);
+  MesherFanMaker(const MesherFanMaker<PrimType> &copy);
+  void operator = (const MesherFanMaker<PrimType> &copy);
 
   INLINE bool operator < (const MesherFanMaker &other) const;
   INLINE bool operator != (const MesherFanMaker &other) const;

+ 4 - 1
panda/src/builder/mesherTempl.I

@@ -534,7 +534,10 @@ find_fans() {
              ++si) {
           Strip *strip = *si;
           if (strip->_type == BPT_tri) {
-            fans.push_back(FanMaker(&v, strip, this));
+            FanMaker fan(&v, strip, this);
+            if (!fan._edges.empty()) {
+              fans.push_back(fan);
+            }
           }
         }
       }