Bladeren bron

more assertions for recompute_bound()

David Rose 20 jaren geleden
bovenliggende
commit
541bbe4403
1 gewijzigde bestanden met toevoegingen van 25 en 3 verwijderingen
  1. 25 3
      panda/src/gobj/geom.cxx

+ 25 - 3
panda/src/gobj/geom.cxx

@@ -1108,11 +1108,33 @@ recompute_bound() {
   // of our vertices.
   pvector<LPoint3f> vertices;
   VertexIterator vi = make_vertex_iterator();
+  int num_vertices = _coords.size();
+  
+  if (_vindex.is_null()) {
+    // Nonindexed case.
+    int vcount = 0;
+    for (int p = 0; p < get_num_prims(); p++) {
+      for (int v = 0; v < get_length(p); v++) {
+        nassertr(vcount < num_vertices, bound);
+        vertices.push_back(get_next_vertex(vi));
+        ++vcount;
+      }
+    }
+    nassertr(vcount == num_vertices, bound);
 
-  for (int p = 0; p < get_num_prims(); p++) {
-    for (int v = 0; v < get_length(p); v++) {
-      vertices.push_back(get_next_vertex(vi));
+  } else {
+    // Indexed case.
+    int num_indices = _vindex.size();
+    int vindex = 0;
+    for (int p = 0; p < get_num_prims(); p++) {
+      for (int v = 0; v < get_length(p); v++) {
+        nassertr(vindex < num_indices, bound);
+        nassertr(_vindex[vindex] < num_vertices, bound);
+        vertices.push_back(get_next_vertex(vi));
+        ++vindex;
+      }
     }
+    nassertr(vindex == num_indices, bound);
   }
 
   const LPoint3f *vertices_begin = &vertices[0];