[Bf-blender-cvs] [b9e82b5] master: Fix T49548: Entering Cycles Rendered Viewport Unlinks Material from Objects.

Bastien Montagne noreply at git.blender.org
Mon Oct 3 17:41:42 CEST 2016


Commit: b9e82b5bfb992c36dd38bca1c9716167b4b9d750
Author: Bastien Montagne
Date:   Mon Oct 3 17:38:14 2016 +0200
Branches: master
https://developer.blender.org/rBb9e82b5bfb992c36dd38bca1c9716167b4b9d750

Fix T49548: Entering Cycles Rendered Viewport Unlinks Material from Objects.

We *always* want to increase mat user count when from Object (and not
Data), because in that case we are moving mat from object to temp
generated mesh, material can never be 'borrowed' in that case.

To be backported to 2.78a

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

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

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

diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c
index 1cc8d8c..2c6ed0d 100644
--- a/source/blender/blenkernel/intern/mesh.c
+++ b/source/blender/blenkernel/intern/mesh.c
@@ -1359,7 +1359,7 @@ void BKE_mesh_from_nurbs_displist(Object *ob, ListBase *dispbase, const bool use
 		}
 
 		/* make mesh */
-		me = BKE_mesh_add(G.main, "Mesh");
+		me = BKE_mesh_add(bmain, "Mesh");
 		me->totvert = totvert;
 		me->totedge = totedge;
 		me->totloop = totloop;
@@ -1379,7 +1379,7 @@ void BKE_mesh_from_nurbs_displist(Object *ob, ListBase *dispbase, const bool use
 		BKE_mesh_calc_normals(me);
 	}
 	else {
-		me = BKE_mesh_add(G.main, "Mesh");
+		me = BKE_mesh_add(bmain, "Mesh");
 		DM_to_mesh(dm, me, ob, CD_MASK_MESH, false);
 	}
 
@@ -2200,7 +2200,7 @@ Mesh *BKE_mesh_new_from_object(
 	int i;
 	const bool render = (settings == eModifierMode_Render);
 	const bool cage = !apply_modifiers;
-	bool do_mat_id_us = true;
+	bool do_mat_id_data_us = true;
 
 	/* perform the mesh extraction based on type */
 	switch (ob->type) {
@@ -2274,7 +2274,7 @@ Mesh *BKE_mesh_new_from_object(
 			/* XXX The curve to mesh conversion is convoluted... But essentially, BKE_mesh_from_nurbs_displist()
 			 *     already transfers the ownership of materials from the temp copy of the Curve ID to the new
 			 *     Mesh ID, so we do not want to increase materials' usercount later. */
-			do_mat_id_us = false;
+			do_mat_id_data_us = false;
 
 			break;
 		}
@@ -2325,7 +2325,7 @@ Mesh *BKE_mesh_new_from_object(
 				tmpmesh = BKE_mesh_copy(bmain, ob->data);
 
 				/* XXX BKE_mesh_copy() already handles materials usercount. */
-				do_mat_id_us = false;
+				do_mat_id_data_us = false;
 			}
 			/* if not getting the original caged mesh, get final derived mesh */
 			else {
@@ -2375,7 +2375,7 @@ Mesh *BKE_mesh_new_from_object(
 						tmpmesh->mat[i] = ob->matbits[i] ? ob->mat[i] : tmpcu->mat[i];
 					}
 
-					if (do_mat_id_us && tmpmesh->mat[i]) {
+					if ((ob->matbits[i] || do_mat_id_data_us)  && tmpmesh->mat[i]) {
 						id_us_plus(&tmpmesh->mat[i]->id);
 					}
 				}
@@ -2399,7 +2399,7 @@ Mesh *BKE_mesh_new_from_object(
 						tmpmesh->mat[i] = ob->matbits[i] ? ob->mat[i] : tmpmb->mat[i];
 					}
 
-					if (do_mat_id_us && tmpmesh->mat[i]) {
+					if ((ob->matbits[i] || do_mat_id_data_us) && tmpmesh->mat[i]) {
 						id_us_plus(&tmpmesh->mat[i]->id);
 					}
 				}
@@ -2424,7 +2424,7 @@ Mesh *BKE_mesh_new_from_object(
 							tmpmesh->mat[i] = ob->matbits[i] ? ob->mat[i] : origmesh->mat[i];
 						}
 
-						if (do_mat_id_us && tmpmesh->mat[i]) {
+						if ((ob->matbits[i] || do_mat_id_data_us)  && tmpmesh->mat[i]) {
 							id_us_plus(&tmpmesh->mat[i]->id);
 						}
 					}




More information about the Bf-blender-cvs mailing list