[Bf-blender-cvs] [e1cd6fae342] master: Avoid Assert in BKE_mesh_calc_loop_tangent_ex

Philipp Oeser noreply at git.blender.org
Sun Oct 18 10:57:51 CEST 2020


Commit: e1cd6fae342519048819231137f25cd8b6d2ee45
Author: Philipp Oeser
Date:   Wed Oct 14 16:16:37 2020 +0200
Branches: master
https://developer.blender.org/rBe1cd6fae342519048819231137f25cd8b6d2ee45

Avoid Assert in BKE_mesh_calc_loop_tangent_ex

Code could call CustomData_get_layer_index_n with a negative index (if
no active and/or render UV layers are found). This would assert since
rBe86785c51445.

Spotted while looking into T81398.

Differential Revision: https://developer.blender.org/D9212

===================================================================

M	source/blender/blenkernel/intern/mesh_tangent.c

===================================================================

diff --git a/source/blender/blenkernel/intern/mesh_tangent.c b/source/blender/blenkernel/intern/mesh_tangent.c
index d6f945cf34f..c8f15fef71a 100644
--- a/source/blender/blenkernel/intern/mesh_tangent.c
+++ b/source/blender/blenkernel/intern/mesh_tangent.c
@@ -724,7 +724,9 @@ void BKE_mesh_calc_loop_tangent_ex(const MVert *mvert,
     *tangent_mask_curr_p = tangent_mask_curr;
 
     /* Update active layer index */
-    int act_uv_index = CustomData_get_layer_index_n(loopdata, CD_MLOOPUV, act_uv_n);
+    int act_uv_index = (act_uv_n != -1) ?
+                           CustomData_get_layer_index_n(loopdata, CD_MLOOPUV, act_uv_n) :
+                           -1;
     if (act_uv_index != -1) {
       int tan_index = CustomData_get_named_layer_index(
           loopdata, CD_TANGENT, loopdata->layers[act_uv_index].name);
@@ -732,7 +734,9 @@ void BKE_mesh_calc_loop_tangent_ex(const MVert *mvert,
     } /* else tangent has been built from orco */
 
     /* Update render layer index */
-    int ren_uv_index = CustomData_get_layer_index_n(loopdata, CD_MLOOPUV, ren_uv_n);
+    int ren_uv_index = (ren_uv_n != -1) ?
+                           CustomData_get_layer_index_n(loopdata, CD_MLOOPUV, ren_uv_n) :
+                           -1;
     if (ren_uv_index != -1) {
       int tan_index = CustomData_get_named_layer_index(
           loopdata, CD_TANGENT, loopdata->layers[ren_uv_index].name);



More information about the Bf-blender-cvs mailing list