Fix regression in recent change 0708733c46
Adding a mirror modifier in edit-mode crashed. Freeing meshes that hold a shallow copy happens in multiple places while calculating modifiers, making it impractical to clear the edit-mode pointer before freeing the mesh (as done in BKE_editmesh_free_derived_caches). Add a struct member to the edit-mesh struct so evaluated copies don't free the edit-mesh contents.
This commit is contained in:
parent
a2f3aca647
commit
a8739ae6c2
Notes:
blender-bot
2023-02-14 04:07:50 +01:00
Referenced by issue #91122, Blender crashes when selecting render passes Cycles
|
@ -78,6 +78,11 @@ typedef struct BMEditMesh {
|
|||
/** Temp variables for x-mirror editing (-1 when the layer does not exist). */
|
||||
int mirror_cdlayer;
|
||||
|
||||
/**
|
||||
* Enable for evaluated copies, causes the edit-mesh to free the memory, not it's contents.
|
||||
*/
|
||||
char is_shallow_copy;
|
||||
|
||||
/**
|
||||
* ID data is older than edit-mode data.
|
||||
* Set #Main.is_memfile_undo_flush_needed when enabling.
|
||||
|
|
|
@ -211,14 +211,10 @@ void BKE_editmesh_looptri_and_normals_calc_with_partial(BMEditMesh *em,
|
|||
void BKE_editmesh_free_derived_caches(BMEditMesh *em)
|
||||
{
|
||||
if (em->mesh_eval_cage) {
|
||||
Mesh *me = em->mesh_eval_cage;
|
||||
me->edit_mesh = NULL;
|
||||
BKE_id_free(NULL, me);
|
||||
BKE_id_free(NULL, em->mesh_eval_cage);
|
||||
}
|
||||
if (em->mesh_eval_final && em->mesh_eval_final != em->mesh_eval_cage) {
|
||||
Mesh *me = em->mesh_eval_final;
|
||||
me->edit_mesh = NULL;
|
||||
BKE_id_free(NULL, me);
|
||||
BKE_id_free(NULL, em->mesh_eval_final);
|
||||
}
|
||||
em->mesh_eval_cage = em->mesh_eval_final = NULL;
|
||||
|
||||
|
|
|
@ -161,7 +161,9 @@ static void mesh_free_data(ID *id)
|
|||
BLI_freelistN(&mesh->vertex_group_names);
|
||||
|
||||
if (mesh->edit_mesh) {
|
||||
BKE_editmesh_free_data(mesh->edit_mesh);
|
||||
if (mesh->edit_mesh->is_shallow_copy == false) {
|
||||
BKE_editmesh_free_data(mesh->edit_mesh);
|
||||
}
|
||||
MEM_freeN(mesh->edit_mesh);
|
||||
mesh->edit_mesh = NULL;
|
||||
}
|
||||
|
|
|
@ -69,7 +69,9 @@ Mesh *BKE_mesh_wrapper_from_editmesh_with_coords(BMEditMesh *em,
|
|||
|
||||
/* Use edit-mesh directly where possible. */
|
||||
me->runtime.is_original = true;
|
||||
me->edit_mesh = em;
|
||||
|
||||
me->edit_mesh = MEM_dupallocN(em);
|
||||
me->edit_mesh->is_shallow_copy = true;
|
||||
|
||||
/* Make sure, we crash if these are ever used. */
|
||||
#ifdef DEBUG
|
||||
|
|
Loading…
Reference in New Issue