Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2020-08-03 07:44:02 +0300
committerCampbell Barton <ideasman42@gmail.com>2020-08-03 07:48:16 +0300
commitd406edf1ee8c69f919d7e7af69c0371b6c93bc51 (patch)
tree5e8f22178708789737ab6d6a6dd7e5a833986ee4 /source
parent0264f53e30c7f5c721766d5f832c12deca14e7ff (diff)
Mesh: correct negative material indices when validating
Fixes corrupt mesh from T79451.
Diffstat (limited to 'source')
-rw-r--r--source/blender/blenkernel/intern/mesh_validate.c15
1 files changed, 13 insertions, 2 deletions
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;
}