Fix: Failing OBJ export tests due to mesh normals commit

In some cases, the normal edit modifier calculated the normals on one
mesh with the "ensure" functions, then copied the mesh and retrieved
the layers "for write" on the copy. Since 59343ee162, normal
layers are never copied, and normals are allocated with malloc instead
of calloc, so the mutable memory was uninitialized.

Fix by calculating normals on the correct mesh, and also add a warning
to the "for write" functions in the header.
This commit is contained in:
Hans Goudey 2022-02-25 17:18:07 -05:00
parent a911f075d7
commit 7aa0be4b32
Notes: blender-bot 2023-02-14 02:30:10 +01:00
Referenced by issue #96111, Terminate called after throwing an instance of ‘Manta::Error’
Referenced by issue #95428, Regression: 3.1 & 3.2 Image/UV Editor poor performance (Byte textures, window dragging, maximizing area)
2 changed files with 8 additions and 2 deletions

View File

@ -414,6 +414,9 @@ void BKE_mesh_assert_normals_dirty_or_calculated(const struct Mesh *mesh);
* \note In order to clear the dirty flag, this function should be followed by a call to
* #BKE_mesh_vertex_normals_clear_dirty. This is separate so that normals are still tagged dirty
* while they are being assigned.
*
* \warning The memory returned by this function is not initialized if it was not previously
* allocated.
*/
float (*BKE_mesh_vertex_normals_for_write(struct Mesh *mesh))[3];
@ -424,6 +427,9 @@ float (*BKE_mesh_vertex_normals_for_write(struct Mesh *mesh))[3];
* \note In order to clear the dirty flag, this function should be followed by a call to
* #BKE_mesh_poly_normals_clear_dirty. This is separate so that normals are still tagged dirty
* while they are being assigned.
*
* \warning The memory returned by this function is not initialized if it was not previously
* allocated.
*/
float (*BKE_mesh_poly_normals_for_write(struct Mesh *mesh))[3];

View File

@ -551,8 +551,8 @@ static Mesh *normalEditModifier_do(NormalEditModifierData *enmd,
CustomData *ldata = &result->ldata;
const float(*vert_normals)[3] = BKE_mesh_vertex_normals_ensure(mesh);
const float(*poly_normals)[3] = BKE_mesh_poly_normals_ensure(mesh);
const float(*vert_normals)[3] = BKE_mesh_vertex_normals_ensure(result);
const float(*poly_normals)[3] = BKE_mesh_poly_normals_ensure(result);
clnors = CustomData_get_layer(ldata, CD_CUSTOMLOOPNORMAL);
if (use_current_clnors) {