Fix T67385: Bind in Laplacian Deform Modifier with new vertex group in Edit Mode...
authorBastien Montagne <montagne29@wanadoo.fr>
Sun, 28 Jul 2019 13:12:38 +0000 (15:12 +0200)
committerBastien Montagne <montagne29@wanadoo.fr>
Sun, 28 Jul 2019 14:11:42 +0000 (16:11 +0200)
Main issue in that report was that meshes generated from
`mesh_create_eval_final_view()` and the like need some
special freeing handling (as, among other things, they borrow and do not
own their potential editmesh data...).

Factorized that into a helper func also used by
`BKE_object_free_derived_caches()`.

source/blender/blenkernel/BKE_mesh.h
source/blender/blenkernel/intern/mesh.c
source/blender/blenkernel/intern/object.c
source/blender/editors/object/object_modifier.c

index 54fbda1fa31c95f849426be9eebc8204853be63b..d6b4fa7228139a292743c041faa5cc71bf828aa6 100644 (file)
@@ -123,6 +123,8 @@ struct Mesh *BKE_mesh_new_nomain_from_template(const struct Mesh *me_src,
                                                int loops_len,
                                                int polys_len);
 
+void BKE_mesh_eval_delete(struct Mesh *me_eval);
+
 /* Performs copy for use during evaluation,
  * optional referencing original arrays to reduce memory. */
 struct Mesh *BKE_mesh_copy_for_eval(struct Mesh *source, bool reference);
index f5e93dcf9b79f107d7a6d686c1dd9eac900a9b0a..9e01bfe62d658f011be92ab10258caf14606dac5 100644 (file)
@@ -697,6 +697,15 @@ Mesh *BKE_mesh_new_nomain_from_template(const Mesh *me_src,
       me_src, verts_len, edges_len, tessface_len, loops_len, polys_len, CD_MASK_EVERYTHING);
 }
 
+void BKE_mesh_eval_delete(struct Mesh *mesh_eval)
+{
+  /* Evaluated mesh may point to edit mesh, but never owns it. */
+  mesh_eval->edit_mesh = NULL;
+  BKE_mesh_free(mesh_eval);
+  BKE_libblock_free_data(&mesh_eval->id, false);
+  MEM_freeN(mesh_eval);
+}
+
 Mesh *BKE_mesh_copy_for_eval(struct Mesh *source, bool reference)
 {
   int flags = LIB_ID_COPY_LOCALIZE;
index d7256cc96040c1f8d78730524a27fc4cde0f3854..69ba7ccab8ea63b0c0049f817bc1340705d78919 100644 (file)
@@ -442,19 +442,13 @@ void BKE_object_free_derived_caches(Object *ob)
   if (ob->runtime.mesh_eval != NULL) {
     if (ob->runtime.is_mesh_eval_owned) {
       Mesh *mesh_eval = ob->runtime.mesh_eval;
-      /* Evaluated mesh points to edit mesh, but does not own it. */
-      mesh_eval->edit_mesh = NULL;
-      BKE_mesh_free(mesh_eval);
-      BKE_libblock_free_data(&mesh_eval->id, false);
-      MEM_freeN(mesh_eval);
+      BKE_mesh_eval_delete(mesh_eval);
     }
     ob->runtime.mesh_eval = NULL;
   }
   if (ob->runtime.mesh_deform_eval != NULL) {
     Mesh *mesh_deform_eval = ob->runtime.mesh_deform_eval;
-    BKE_mesh_free(mesh_deform_eval);
-    BKE_libblock_free_data(&mesh_deform_eval->id, false);
-    MEM_freeN(mesh_deform_eval);
+    BKE_mesh_eval_delete(mesh_deform_eval);
     ob->runtime.mesh_deform_eval = NULL;
   }
 
index 08012842c37a87ac912a1efb1f744ea127b765da..e72bf1ea10a8ba135cbf36d6b7b5a678c4751fd6 100644 (file)
@@ -99,7 +99,7 @@ static void object_force_modifier_update_for_bind(Depsgraph *depsgraph, Object *
   BKE_object_eval_reset(ob_eval);
   if (ob->type == OB_MESH) {
     Mesh *me_eval = mesh_create_eval_final_view(depsgraph, scene_eval, ob_eval, &CD_MASK_BAREMESH);
-    BKE_id_free(NULL, me_eval);
+    BKE_mesh_eval_delete(me_eval);
   }
   else if (ob->type == OB_LATTICE) {
     BKE_lattice_modifiers_calc(depsgraph, scene_eval, ob_eval);