Fix T54098: Crash existing /w dyntopo sculpt
authorCampbell Barton <ideasman42@gmail.com>
Mon, 19 Feb 2018 06:27:01 +0000 (17:27 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 19 Feb 2018 06:34:30 +0000 (17:34 +1100)
Optionally don't remap indices for objects.

Checking all objects parent's would reference a freed pointer
while freeing all objects.

In the case of dynamic topology there is no use in keeping track
of hook/vertex-parent indices.

Also disable this when creating meshes for undo storage
since adding an undo step shouldn't be modifying other objects.

source/blender/blenkernel/intern/scene.c
source/blender/bmesh/intern/bmesh_mesh_conv.c
source/blender/bmesh/intern/bmesh_mesh_conv.h
source/blender/bmesh/operators/bmo_mesh_conv.c
source/blender/editors/mesh/editmesh_tools.c
source/blender/editors/mesh/editmesh_undo.c
source/blender/editors/mesh/editmesh_utils.c
source/blender/python/bmesh/bmesh_py_types.c

index 126761ed14bc17b4080815f9c852f3304be1847e..423ed2af057ad698dd211b4d7216d54ca3afb9d7 100644 (file)
@@ -1851,7 +1851,11 @@ static void prepare_mesh_for_viewport_render(Main *bmain, Scene *scene)
                {
                        if (check_rendered_viewport_visible(bmain)) {
                                BMesh *bm = mesh->edit_btmesh->bm;
-                               BM_mesh_bm_to_me(bm, mesh, (&(struct BMeshToMeshParams){0}));
+                               BM_mesh_bm_to_me(
+                                       bm, mesh,
+                                       (&(struct BMeshToMeshParams){
+                                           .calc_object_remap = true,
+                                       }));
                                DAG_id_tag_update(&mesh->id, 0);
                        }
                }
index 7787d704b59d0614c5edad1cfd1a2257818eca7c..4b86ac03d7f577bd5cba614844ff684d68c6ff91 100644 (file)
@@ -751,7 +751,7 @@ void BM_mesh_bm_to_me(
        }
 
        /* patch hook indices and vertex parents */
-       if (ototvert > 0) {
+       if (params->calc_object_remap && (ototvert > 0)) {
                Object *ob;
                ModifierData *md;
                BMVert **vertMap = NULL;
index 1974d364171d06975ada2c8dec3835511b8591f9..e6072f7b5f29eeb3b98e6064de1c9ceac5adb7ed 100644 (file)
@@ -56,6 +56,8 @@ ATTR_NONNULL(1, 3);
 
 struct BMeshToMeshParams {
        uint calc_tessface : 1;
+       /** Update object hook indices & vertex parents. */
+       uint calc_object_remap : 1;
        int64_t cd_mask_extra;
 };
 void BM_mesh_bm_to_me(
index 0eb9bf90ca812eafe87d5069371064a98c6e77cf..981930705b3681c22c61d36bc526fbdcd4ab7307 100644 (file)
@@ -72,5 +72,10 @@ void bmo_bmesh_to_mesh_exec(BMesh *bm, BMOperator *op)
        /* Object *ob = BMO_slot_ptr_get(op, "object"); */
        const bool dotess = !BMO_slot_bool_get(op->slots_in, "skip_tessface");
 
-       BM_mesh_bm_to_me(bm, me, (&(struct BMeshToMeshParams){ .calc_tessface = dotess, }));
+       BM_mesh_bm_to_me(
+               bm, me,
+               (&(struct BMeshToMeshParams){
+                   .calc_tessface = dotess,
+                   .calc_object_remap = true,
+               }));
 }
index 4b4f1b2afeafe9e3fcdba6bff2145c049f03994f..c979a73e9645b70985d681b26fb1dd0885c5b74c 100644 (file)
@@ -3357,7 +3357,11 @@ static int edbm_separate_exec(bContext *C, wmOperator *op)
                                        }
 
                                        if (retval_iter) {
-                                               BM_mesh_bm_to_me(bm_old, me, (&(struct BMeshToMeshParams){0}));
+                                               BM_mesh_bm_to_me(
+                                                       bm_old, me,
+                                                       (&(struct BMeshToMeshParams){
+                                                           .calc_object_remap = true,
+                                                       }));
 
                                                DAG_id_tag_update(&me->id, OB_RECALC_DATA);
                                                WM_event_add_notifier(C, NC_GEOM | ND_DATA, me);
index 534ca22178eabfd1c9a5b6284d9395bb51fdde65..11667ed571051068361ed7c3ed4e1bf1b0340a51 100644 (file)
@@ -496,6 +496,8 @@ static void *editbtMesh_to_undoMesh(void *emv, void *obdata)
 
        BM_mesh_bm_to_me(
                em->bm, &um->me, (&(struct BMeshToMeshParams){
+                   /* Undo code should not be manipulating 'G.main->object' hooks/vertex-parent. */
+                   .calc_object_remap = false,
                    .cd_mask_extra = CD_MASK_SHAPE_KEYINDEX,
                }));
 
index e407d342603241ffffc8fec615e23892e7c7db9b..c4440fa190ad463a6675b6d0e6c1d69227034cf7 100644 (file)
@@ -380,7 +380,10 @@ void EDBM_mesh_load(Object *ob)
                bm->shapenr = 1;
        }
 
-       BM_mesh_bm_to_me(bm, me, (&(struct BMeshToMeshParams){0}));
+       BM_mesh_bm_to_me(
+               bm, me, (&(struct BMeshToMeshParams){
+                   .calc_object_remap = true,
+               }));
 
 #ifdef USE_TESSFACE_DEFAULT
        BKE_mesh_tessface_calc(me);
index 6ab5ebf3c81e66e6f8a1c050656971544ba005bc..2866683b89b81a1ea47dbebfb0c17c70738e7791 100644 (file)
@@ -904,7 +904,11 @@ static PyObject *bpy_bmesh_to_mesh(BPy_BMesh *self, PyObject *args)
        /* python won't ensure matching uv/mtex */
        BM_mesh_cd_validate(bm);
 
-       BM_mesh_bm_to_me(bm, me, (&(struct BMeshToMeshParams){0}));
+       BM_mesh_bm_to_me(
+               bm, me,
+               (&(struct BMeshToMeshParams){
+                   .calc_object_remap = true,
+               }));
 
        /* we could have the user do this but if they forget blender can easy crash
         * since the references arrays for the objects derived meshes are now invalid */