Fix T49623: Immediately crash trying to render attached file in Cycles
authorSergey Sharybin <sergey.vfx@gmail.com>
Tue, 11 Oct 2016 09:54:04 +0000 (11:54 +0200)
committerSergey Sharybin <sergey.vfx@gmail.com>
Tue, 11 Oct 2016 09:55:11 +0000 (11:55 +0200)
Original fix in this area was not really complete (but was the safest at
the release time). Now all the crazy configurations of slots going out
of sync should be handled here.

source/blender/blenkernel/intern/mesh.c

index 2c6ed0df04b274ca5630bcff70e7c7ac706913a2..446aef9be65a0d898e3ffbd4591bdf0227ea9231 100644 (file)
@@ -2368,14 +2368,9 @@ Mesh *BKE_mesh_new_from_object(
                        if (tmpcu->mat) {
                                for (i = tmpcu->totcol; i-- > 0; ) {
                                        /* are we an object material or data based? */
-                                       if (ob->matbits[i] && i >= ob->totcol) {
-                                               tmpmesh->mat[i] = NULL;
-                                       }
-                                       else {
-                                               tmpmesh->mat[i] = ob->matbits[i] ? ob->mat[i] : tmpcu->mat[i];
-                                       }
+                                       tmpmesh->mat[i] = give_current_material(ob, i + 1);
 
-                                       if ((ob->matbits[i] || do_mat_id_data_us)  && tmpmesh->mat[i]) {
+                                       if (((ob->matbits && ob->matbits[i]) || do_mat_id_data_us)  && tmpmesh->mat[i]) {
                                                id_us_plus(&tmpmesh->mat[i]->id);
                                        }
                                }
@@ -2392,14 +2387,9 @@ Mesh *BKE_mesh_new_from_object(
                        if (tmpmb->mat) {
                                for (i = tmpmb->totcol; i-- > 0; ) {
                                        /* are we an object material or data based? */
-                                       if (ob->matbits[i] && i >= ob->totcol) {
-                                               tmpmesh->mat[i] = NULL;
-                                       }
-                                       else {
-                                               tmpmesh->mat[i] = ob->matbits[i] ? ob->mat[i] : tmpmb->mat[i];
-                                       }
+                                       tmpmesh->mat[i] = give_current_material(ob, i + 1);
 
-                                       if ((ob->matbits[i] || do_mat_id_data_us) && tmpmesh->mat[i]) {
+                                       if (((ob->matbits[i] && ob->matbits) || do_mat_id_data_us) && tmpmesh->mat[i]) {
                                                id_us_plus(&tmpmesh->mat[i]->id);
                                        }
                                }
@@ -2417,14 +2407,9 @@ Mesh *BKE_mesh_new_from_object(
                                if (origmesh->mat) {
                                        for (i = origmesh->totcol; i-- > 0; ) {
                                                /* are we an object material or data based? */
-                                               if (ob->matbits[i] && i >= ob->totcol) {
-                                                       tmpmesh->mat[i] = NULL;
-                                               }
-                                               else {
-                                                       tmpmesh->mat[i] = ob->matbits[i] ? ob->mat[i] : origmesh->mat[i];
-                                               }
+                                               tmpmesh->mat[i] = give_current_material(ob, i + 1);
 
-                                               if ((ob->matbits[i] || do_mat_id_data_us)  && tmpmesh->mat[i]) {
+                                               if (((ob->matbits && ob->matbits[i]) || do_mat_id_data_us)  && tmpmesh->mat[i]) {
                                                        id_us_plus(&tmpmesh->mat[i]->id);
                                                }
                                        }