Fix T65638: memory leak - modifiers on curves.
authorBastien Montagne <montagne29@wanadoo.fr>
Sun, 9 Jun 2019 19:11:37 +0000 (21:11 +0200)
committerBastien Montagne <montagne29@wanadoo.fr>
Sun, 9 Jun 2019 19:11:37 +0000 (21:11 +0200)
We need to tag the `mesh_eval` of curve as owned, when we generate one,
otherwise freeing code would not free it.

source/blender/blenkernel/intern/displist.c
source/blender/blenkernel/intern/mesh_convert.c

index b673352..cf6f1fd 100644 (file)
@@ -1159,6 +1159,10 @@ static void curve_calc_modifiers_post(Depsgraph *depsgraph,
       (*r_final) = NULL;
     }
   }
+  else if (modified != NULL) {
+    /* Prety stupid to generate that whole mesh if it's unused, yet we have to free it. */
+    BKE_id_free(NULL, modified);
+  }
 }
 
 static void displist_surf_indices(DispList *dl)
@@ -1808,6 +1812,11 @@ void BKE_displist_make_curveTypes(
   do_makeDispListCurveTypes(
       depsgraph, scene, ob, dispbase, for_render, for_orco, &ob->runtime.mesh_eval);
 
+  if (ob->runtime.mesh_eval != NULL) {
+    ob->runtime.mesh_eval->id.tag |= LIB_TAG_COPIED_ON_WRITE_EVAL_RESULT;
+    ob->runtime.is_mesh_eval_owned = true;
+  }
+
   boundbox_displist_object(ob);
 }
 
index f99dee7..dd36da4 100644 (file)
@@ -1007,6 +1007,14 @@ static void curve_to_mesh_eval_ensure(Object *object)
                                          &remapped_object.runtime.mesh_eval,
                                          false);
 
+  /* Note: this is to be consistent with `BKE_displist_make_curveTypes()`, however that is not a
+   * real issue currently, code here is broken in more than one way, fix(es) will be done
+   * separately. */
+  if (remapped_object.runtime.mesh_eval != NULL) {
+    remapped_object.runtime.mesh_eval->id.tag |= LIB_TAG_COPIED_ON_WRITE_EVAL_RESULT;
+    remapped_object.runtime.is_mesh_eval_owned = true;
+  }
+
   BKE_object_free_curve_cache(&bevel_object);
   BKE_object_free_curve_cache(&taper_object);
 }