Fix possible concurency issue in mesh normals computation.
authorBastien Montagne <montagne29@wanadoo.fr>
Wed, 31 Jan 2018 11:30:39 +0000 (12:30 +0100)
committerBastien Montagne <montagne29@wanadoo.fr>
Wed, 31 Jan 2018 11:30:39 +0000 (12:30 +0100)
Failure in own code from last December, thanks @sergey for finding it.

To be backported to 2.79a.

source/blender/blenkernel/intern/mesh_evaluate.c

index f95fad38c7c9caf2ab39f4f4ef2bff6c3092b3b5..425f28eb12340539f3886eb314dfe0ade1f26f60 100644 (file)
@@ -253,16 +253,6 @@ static void mesh_calc_normals_poly_prepare_cb(
        }
 }
 
-static void mesh_calc_normals_poly_accum_cb(
-        void *__restrict userdata,
-        const int lidx,
-        const ParallelRangeTLS *__restrict UNUSED(tls))
-{
-       MeshCalcNormalsData *data = userdata;
-
-       add_v3_v3(data->vnors[data->mloop[lidx].v], data->lnors_weighted[lidx]);
-}
-
 static void mesh_calc_normals_poly_finalize_cb(
         void *__restrict userdata,
         const int vidx,
@@ -327,7 +317,11 @@ void BKE_mesh_calc_normals_poly(
        BLI_task_parallel_range(0, numPolys, &data, mesh_calc_normals_poly_prepare_cb, &settings);
 
        /* Actually accumulate weighted loop normals into vertex ones. */
-       BLI_task_parallel_range(0, numLoops, &data, mesh_calc_normals_poly_accum_cb, &settings);
+       /* Unfortunately, not possible to thread that (not in a reasonable, totally lock- and barrier-free fashion),
+        * since several loops will point to the same vertex... */
+       for (int lidx = 0; lidx < numLoops; lidx++) {
+               add_v3_v3(vnors[mloop[lidx].v], data.lnors_weighted[lidx]);
+       }
 
        /* Normalize and validate computed vertex normals. */
        BLI_task_parallel_range(0, numVerts, &data, mesh_calc_normals_poly_finalize_cb, &settings);