Fix for crash when sculpting on multires object during playback
authorSergey Sharybin <sergey.vfx@gmail.com>
Sun, 20 Feb 2011 15:35:01 +0000 (15:35 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Sun, 20 Feb 2011 15:35:01 +0000 (15:35 +0000)
- Restored BLI_pbvh_grids_update stuff;
- Marc all nodes as changes in ED_sculpt_modifiers_changed, so
  draw_buffers would be keept correct.

source/blender/blenkernel/intern/subsurf_ccg.c
source/blender/blenlib/BLI_pbvh.h
source/blender/blenlib/intern/pbvh.c
source/blender/editors/sculpt_paint/sculpt.c

index 0889f490e797e202bde7b5112522f66fe3ae27c4..9b4b9a78dd4717d0a488b5dee1bb7fa506b5df3c 100644 (file)
@@ -2251,8 +2251,16 @@ static struct PBVH *ccgDM_getPBVH(Object *ob, DerivedMesh *dm)
        if(!ob->sculpt)
                return NULL;
 
-       if(ob->sculpt->pbvh)
+       if(ob->sculpt->pbvh) {
+          /* pbvh's grids, gridadj and gridfaces points to data inside ccgdm
+                 but this can be freed on ccgdm release, this updates the pointers
+                 when the ccgdm gets remade, the assumption is that the topology
+                 does not change. */
+               ccgdm_create_grids(dm);
+               BLI_pbvh_grids_update(ob->sculpt->pbvh, ccgdm->gridData, ccgdm->gridAdjacency, (void**)ccgdm->gridFaces);
+
                ccgdm->pbvh = ob->sculpt->pbvh;
+       }
 
        if(ccgdm->pbvh)
                return ccgdm->pbvh;
index 4191559771d6be4a20f1f84d3811a175886de328..bde6bc3ced4d270f4f7397697c38d8c1b367ea80 100644 (file)
@@ -121,6 +121,8 @@ float BLI_pbvh_node_get_tmin(PBVHNode* node);
 void BLI_pbvh_update(PBVH *bvh, int flags, float (*face_nors)[3]);
 void BLI_pbvh_redraw_BB(PBVH *bvh, float bb_min[3], float bb_max[3]);
 void BLI_pbvh_get_grid_updates(PBVH *bvh, int clear, void ***gridfaces, int *totface);
+void BLI_pbvh_grids_update(PBVH *bvh, struct DMGridData **grids,
+       struct DMGridAdjacency *gridadj, void **gridfaces);;
 
 /* vertex deformer */
 float (*BLI_pbvh_get_vertCos(struct PBVH *pbvh))[3];
index 3c7300f258896ac81b4aae1e869472d4d6e4f8d0..880664fd55ded39de151db993aac76932cf299cc 100644 (file)
@@ -1475,6 +1475,13 @@ void BLI_pbvh_draw(PBVH *bvh, float (*planes)[4], float (*face_nors)[3], int smo
        }
 }
 
+void BLI_pbvh_grids_update(PBVH *bvh, DMGridData **grids, DMGridAdjacency *gridadj, void **gridfaces)
+{
+       bvh->grids= grids;
+       bvh->gridadj= gridadj;
+       bvh->gridfaces= gridfaces;
+}
+
 float (*BLI_pbvh_get_vertCos(PBVH *pbvh))[3]
 {
        int a;
index fa8d61d73ded9d58e05ac3073afa952d59533ed2..fa44cd5b122b7f654af056ef667d82592d2e9b09 100644 (file)
@@ -109,6 +109,16 @@ void ED_sculpt_modifiers_changed(Object *ob)
                }
 
                sculpt_free_deformMats(ob->sculpt);
+       } else {
+               PBVHNode **nodes;
+               int n, totnode;
+
+               BLI_pbvh_search_gather(ss->pbvh, NULL, NULL, &nodes, &totnode);
+
+               for(n = 0; n < totnode; n++)
+                       BLI_pbvh_node_mark_update(nodes[n]);
+
+               MEM_freeN(nodes);
        }
 }