[Bf-blender-cvs] [daa1487] blender-v2.78-release: Cycles: Prevent crash in special cases when object has less slots than mesh

Sergey Sharybin noreply at git.blender.org
Mon Sep 26 10:54:14 CEST 2016


Commit: daa1487425b105dbe74c2e784ca52ea03ed7d874
Author: Sergey Sharybin
Date:   Fri Sep 23 15:57:39 2016 +0200
Branches: blender-v2.78-release
https://developer.blender.org/rBdaa1487425b105dbe74c2e784ca52ea03ed7d874

Cycles: Prevent crash in special cases when object has less slots than mesh

This is something what was guaranteed in give_current_material(), just
copied some range checking logic from there.

Not sure what would be a proper fix here tho.

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

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

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

diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c
index ba3aef8..49e3558 100644
--- a/source/blender/blenkernel/intern/mesh.c
+++ b/source/blender/blenkernel/intern/mesh.c
@@ -2368,8 +2368,12 @@ Mesh *BKE_mesh_new_from_object(
 			if (tmpcu->mat) {
 				for (i = tmpcu->totcol; i-- > 0; ) {
 					/* are we an object material or data based? */
-
-					tmpmesh->mat[i] = ob->matbits[i] ? ob->mat[i] : tmpcu->mat[i];
+					if (ob->matbits[i] && i >= ob->totcol) {
+						tmpmesh->mat[i] = NULL;
+					}
+					else {
+						tmpmesh->mat[i] = ob->matbits[i] ? ob->mat[i] : tmpcu->mat[i];
+					}
 
 					if (do_mat_id_us && tmpmesh->mat[i]) {
 						id_us_plus(&tmpmesh->mat[i]->id);
@@ -2388,7 +2392,12 @@ Mesh *BKE_mesh_new_from_object(
 			if (tmpmb->mat) {
 				for (i = tmpmb->totcol; i-- > 0; ) {
 					/* are we an object material or data based? */
-					tmpmesh->mat[i] = ob->matbits[i] ? ob->mat[i] : tmpmb->mat[i];
+					if (ob->matbits[i] && i >= ob->totcol) {
+						tmpmesh->mat[i] = NULL;
+					}
+					else {
+						tmpmesh->mat[i] = ob->matbits[i] ? ob->mat[i] : tmpmb->mat[i];
+					}
 
 					if (do_mat_id_us && tmpmesh->mat[i]) {
 						id_us_plus(&tmpmesh->mat[i]->id);
@@ -2408,7 +2417,12 @@ Mesh *BKE_mesh_new_from_object(
 				if (origmesh->mat) {
 					for (i = origmesh->totcol; i-- > 0; ) {
 						/* are we an object material or data based? */
-						tmpmesh->mat[i] = ob->matbits[i] ? ob->mat[i] : origmesh->mat[i];
+						if (ob->matbits[i] && i >= ob->totcol) {
+							tmpmesh->mat[i] = NULL;
+						}
+						else {
+							tmpmesh->mat[i] = ob->matbits[i] ? ob->mat[i] : origmesh->mat[i];
+						}
 
 						if (do_mat_id_us && tmpmesh->mat[i]) {
 							id_us_plus(&tmpmesh->mat[i]->id);




More information about the Bf-blender-cvs mailing list