[Bf-blender-cvs] [d406edf1ee8] blender-v2.90-release: Mesh: correct negative material indices when validating
Campbell Barton
noreply at git.blender.org
Mon Aug 3 06:54:02 CEST 2020
Commit: d406edf1ee8c69f919d7e7af69c0371b6c93bc51
Author: Campbell Barton
Date: Mon Aug 3 14:44:02 2020 +1000
Branches: blender-v2.90-release
https://developer.blender.org/rBd406edf1ee8c69f919d7e7af69c0371b6c93bc51
Mesh: correct negative material indices when validating
Fixes corrupt mesh from T79451.
===================================================================
M source/blender/blenkernel/intern/mesh_validate.c
===================================================================
diff --git a/source/blender/blenkernel/intern/mesh_validate.c b/source/blender/blenkernel/intern/mesh_validate.c
index f64ed609d18..4d8c0568eb6 100644
--- a/source/blender/blenkernel/intern/mesh_validate.c
+++ b/source/blender/blenkernel/intern/mesh_validate.c
@@ -547,6 +547,16 @@ bool BKE_mesh_validate_arrays(Mesh *mesh,
for (i = 0, mp = mpolys; i < totpoly; i++, mp++, sp++) {
sp->index = i;
+ /* Material index, isolated from other tests here. While large indices are clamped,
+ * negative indices aren't supported by drawing, exporters etc.
+ * To check the indices are in range, use #BKE_mesh_validate_material_indices */
+ if (mp->mat_nr < 0) {
+ PRINT_ERR("\tPoly %u has invalid material (%d)", sp->index, mp->mat_nr);
+ if (do_fixes) {
+ mp->mat_nr = 0;
+ }
+ }
+
if (mp->loopstart < 0 || mp->totloop < 3) {
/* Invalid loop data. */
PRINT_ERR("\tPoly %u is invalid (loopstart: %d, totloop: %d)",
@@ -1133,14 +1143,15 @@ bool BKE_mesh_is_valid(Mesh *me)
*/
bool BKE_mesh_validate_material_indices(Mesh *me)
{
+ /* Cast to unsigned to catch negative indices too. */
+ const uint16_t mat_nr_max = max_ii(0, me->totcol - 1);
MPoly *mp;
- const int max_idx = max_ii(0, me->totcol - 1);
const int totpoly = me->totpoly;
int i;
bool is_valid = true;
for (mp = me->mpoly, i = 0; i < totpoly; i++, mp++) {
- if (mp->mat_nr > max_idx) {
+ if ((uint16_t)mp->mat_nr > mat_nr_max) {
mp->mat_nr = 0;
is_valid = false;
}
More information about the Bf-blender-cvs
mailing list