Commit: a7904dff4be5f7c0782e2cec618defda2c27c8a3
Author: Pablo Dobarro
Date:   Mon Sep 23 18:07:28 2019 +0200
Branches: master
https://developer.blender.org/rBa7904dff4be5f7c0782e2cec618defda2c27c8a3

Fix crash in dynamic mesh preview edge list update

Reviewed By: jbakker

Differential Revision: https://developer.blender.org/D5824

===================================================================

M       source/blender/editors/sculpt_paint/sculpt.c

===================================================================

diff --git a/source/blender/editors/sculpt_paint/sculpt.c 
b/source/blender/editors/sculpt_paint/sculpt.c
index 52cb02f1f12..f31c2db9191 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -9116,9 +9116,11 @@ void sculpt_geometry_preview_lines_update(bContext *C, 
SculptSession *ss, float
   char *visited_vertices = MEM_callocN(sculpt_vertex_count_get(ss) * 
sizeof(char),
                                        "visited vertices");
 
+  /* Assuming an average of 6 edges per vertex in a triangulated mesh */
+  const int max_preview_vertices = sculpt_vertex_count_get(ss) * 3 * 2;
+
   if (ss->preview_vert_index_list == NULL) {
-    ss->preview_vert_index_list = MEM_callocN(4 * sizeof(int) * 
sculpt_vertex_count_get(ss),
-                                              "preview lines");
+    ss->preview_vert_index_list = MEM_callocN(max_preview_vertices * 
sizeof(int), "preview lines");
   }
 
   BLI_Stack *not_visited_vertices = 
BLI_stack_new(sizeof(VertexTopologyIterator),
@@ -9133,17 +9135,20 @@ void sculpt_geometry_preview_lines_update(bContext *C, 
SculptSession *ss, float
     SculptVertexNeighborIter ni;
     sculpt_vertex_neighbors_iter_begin(ss, c_mevit.v, ni)
     {
-      VertexTopologyIterator new_entry;
-      new_entry.v = ni.index;
-      new_entry.it = c_mevit.it + 1;
-      ss->preview_vert_index_list[totpoints] = c_mevit.v;
-      totpoints++;
-      ss->preview_vert_index_list[totpoints] = new_entry.v;
-      totpoints++;
-      if (visited_vertices[(int)ni.index] == 0) {
-        visited_vertices[(int)ni.index] = 1;
-        if (len_squared_v3v3(brush_co, sculpt_vertex_co_get(ss, new_entry.v)) 
< radius * radius) {
-          BLI_stack_push(not_visited_vertices, &new_entry);
+      if (totpoints + (ni.size * 2) < max_preview_vertices) {
+        VertexTopologyIterator new_entry;
+        new_entry.v = ni.index;
+        new_entry.it = c_mevit.it + 1;
+        ss->preview_vert_index_list[totpoints] = c_mevit.v;
+        totpoints++;
+        ss->preview_vert_index_list[totpoints] = new_entry.v;
+        totpoints++;
+        if (visited_vertices[(int)ni.index] == 0) {
+          visited_vertices[(int)ni.index] = 1;
+          if (len_squared_v3v3(brush_co, sculpt_vertex_co_get(ss, 
new_entry.v)) <
+              radius * radius) {
+            BLI_stack_push(not_visited_vertices, &new_entry);
+          }
         }
       }
     }

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to