Fix T67385: Bind in Laplacian Deform Modifier with new vertex group in Edit Mode crashes Blender.
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()`.
This commit is contained in:
parent
c4cf14d161
commit
3e45f01494
Notes:
blender-bot
2023-02-14 05:37:19 +01:00
Referenced by issue #67385, Bind in Laplacian Deform Modifier with new vertex group in Edit Mode crashes Blender
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue