Fix memory leak calculating deform modifiers in edit-mode
This bug goes back to 2.80 but doesn't seem to have been reported.
This commit is contained in:
@@ -49,6 +49,7 @@ void BKE_mesh_runtime_looptri_recalc(struct Mesh *mesh);
|
||||
const struct MLoopTri *BKE_mesh_runtime_looptri_ensure(struct Mesh *mesh);
|
||||
bool BKE_mesh_runtime_ensure_edit_data(struct Mesh *mesh);
|
||||
bool BKE_mesh_runtime_clear_edit_data(struct Mesh *mesh);
|
||||
bool BKE_mesh_runtime_reset_edit_data(struct Mesh *mesh);
|
||||
void BKE_mesh_runtime_clear_geometry(struct Mesh *mesh);
|
||||
void BKE_mesh_runtime_clear_cache(struct Mesh *mesh);
|
||||
|
||||
|
||||
@@ -1669,7 +1669,9 @@ static void editbmesh_calc_modifiers(struct Depsgraph *depsgraph,
|
||||
else {
|
||||
Mesh *me_orig = mesh_input;
|
||||
if (me_orig->id.tag & LIB_TAG_COPIED_ON_WRITE) {
|
||||
BKE_mesh_runtime_ensure_edit_data(me_orig);
|
||||
if (!BKE_mesh_runtime_ensure_edit_data(me_orig)) {
|
||||
BKE_mesh_runtime_reset_edit_data(me_orig);
|
||||
}
|
||||
me_orig->runtime.edit_data->vertexCos = MEM_dupallocN(deformed_verts);
|
||||
}
|
||||
mesh_cage = BKE_mesh_wrapper_from_editmesh_with_coords(
|
||||
|
||||
@@ -203,26 +203,31 @@ bool BKE_mesh_runtime_ensure_edit_data(struct Mesh *mesh)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BKE_mesh_runtime_reset_edit_data(Mesh *mesh)
|
||||
{
|
||||
EditMeshData *edit_data = mesh->runtime.edit_data;
|
||||
if (edit_data == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
MEM_SAFE_FREE(edit_data->polyCos);
|
||||
MEM_SAFE_FREE(edit_data->polyNos);
|
||||
MEM_SAFE_FREE(edit_data->vertexCos);
|
||||
MEM_SAFE_FREE(edit_data->vertexNos);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BKE_mesh_runtime_clear_edit_data(Mesh *mesh)
|
||||
{
|
||||
if (mesh->runtime.edit_data == NULL) {
|
||||
return false;
|
||||
}
|
||||
BKE_mesh_runtime_reset_edit_data(mesh);
|
||||
|
||||
if (mesh->runtime.edit_data->polyCos != NULL) {
|
||||
MEM_freeN((void *)mesh->runtime.edit_data->polyCos);
|
||||
}
|
||||
if (mesh->runtime.edit_data->polyNos != NULL) {
|
||||
MEM_freeN((void *)mesh->runtime.edit_data->polyNos);
|
||||
}
|
||||
if (mesh->runtime.edit_data->vertexCos != NULL) {
|
||||
MEM_freeN((void *)mesh->runtime.edit_data->vertexCos);
|
||||
}
|
||||
if (mesh->runtime.edit_data->vertexNos != NULL) {
|
||||
MEM_freeN((void *)mesh->runtime.edit_data->vertexNos);
|
||||
}
|
||||
MEM_freeN(mesh->runtime.edit_data);
|
||||
mesh->runtime.edit_data = NULL;
|
||||
|
||||
MEM_SAFE_FREE(mesh->runtime.edit_data);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user