Fix T65285: Crash with Object.to_mesh() in certain conditions

Was happening when modifier stack detected that mesh is not deformed
and is not modified and attempted to share result across multiple
objects.

This was introduced in 2f77119.

Now functions which are supposed to return mesh owned by caller will
do so again. Shouldn't be a huge impact on memory print since the
data layers are referenced.
This commit is contained in:
Sergey Sharybin 2019-05-31 10:05:56 +02:00
parent 2c4a9f7718
commit 963917e1b9
Notes: blender-bot 2023-02-14 02:23:17 +01:00
Referenced by issue #79965, Stateful behavior with ID.evaluated_get(..) and Object.to_mesh(preserve_all_data_layers=True, ..)
Referenced by issue #65285, Object.to_mesh(preserve_all_data_layers=True, depsgraph=depsgraph) with no modifiers or shapekeys = crash
1 changed files with 8 additions and 6 deletions

View File

@ -1129,6 +1129,7 @@ static void mesh_calc_modifiers(struct Depsgraph *depsgraph,
const CustomData_MeshMasks *dataMask,
const int index,
const bool use_cache,
const bool allow_shared_mesh,
/* return args */
Mesh **r_deform,
Mesh **r_final)
@ -1538,7 +1539,7 @@ static void mesh_calc_modifiers(struct Depsgraph *depsgraph,
* need to apply these back onto the Mesh. If we have no
* Mesh then we need to build one. */
if (mesh_final == NULL) {
if (deformed_verts == NULL) {
if (deformed_verts == NULL && allow_shared_mesh) {
mesh_final = mesh_input;
}
else {
@ -2053,6 +2054,7 @@ static void mesh_build_data(struct Depsgraph *depsgraph,
dataMask,
-1,
true,
true,
&ob->runtime.mesh_deform_eval,
&ob->runtime.mesh_eval);
@ -2253,7 +2255,7 @@ Mesh *mesh_create_eval_final_render(Depsgraph *depsgraph,
{
Mesh *final;
mesh_calc_modifiers(depsgraph, scene, ob, 1, false, dataMask, -1, false, NULL, &final);
mesh_calc_modifiers(depsgraph, scene, ob, 1, false, dataMask, -1, false, false, NULL, &final);
return final;
}
@ -2266,7 +2268,7 @@ Mesh *mesh_create_eval_final_index_render(Depsgraph *depsgraph,
{
Mesh *final;
mesh_calc_modifiers(depsgraph, scene, ob, 1, false, dataMask, index, false, NULL, &final);
mesh_calc_modifiers(depsgraph, scene, ob, 1, false, dataMask, index, false, false, NULL, &final);
return final;
}
@ -2284,7 +2286,7 @@ Mesh *mesh_create_eval_final_view(Depsgraph *depsgraph,
*/
ob->transflag |= OB_NO_PSYS_UPDATE;
mesh_calc_modifiers(depsgraph, scene, ob, 1, false, dataMask, -1, false, NULL, &final);
mesh_calc_modifiers(depsgraph, scene, ob, 1, false, dataMask, -1, false, false, NULL, &final);
ob->transflag &= ~OB_NO_PSYS_UPDATE;
@ -2298,7 +2300,7 @@ Mesh *mesh_create_eval_no_deform(Depsgraph *depsgraph,
{
Mesh *final;
mesh_calc_modifiers(depsgraph, scene, ob, 0, false, dataMask, -1, false, NULL, &final);
mesh_calc_modifiers(depsgraph, scene, ob, 0, false, dataMask, -1, false, false, NULL, &final);
return final;
}
@ -2310,7 +2312,7 @@ Mesh *mesh_create_eval_no_deform_render(Depsgraph *depsgraph,
{
Mesh *final;
mesh_calc_modifiers(depsgraph, scene, ob, 0, false, dataMask, -1, false, NULL, &final);
mesh_calc_modifiers(depsgraph, scene, ob, 0, false, dataMask, -1, false, false, NULL, &final);
return final;
}