[Bf-blender-cvs] [1270ab9] master: Fix T48898: shaders are removed from metaballs on cycles render.

Bastien Montagne noreply at git.blender.org
Wed Jul 20 16:44:42 CEST 2016


Commit: 1270ab91be53fd90e404e6366c73cc99ba470b14
Author: Bastien Montagne
Date:   Wed Jul 20 16:29:54 2016 +0200
Branches: master
https://developer.blender.org/rB1270ab91be53fd90e404e6366c73cc99ba470b14

Fix T48898: shaders are removed from metaballs on cycles render.

Note that issue has several levels here actually, first one was metaball's materials
not being properly copied into new mesh (code was commented out because of some crash it
seems, made it a bit closer to mesh one and got no crash at all...).

Then, we were calling test_object_materials when ob->data is actually *not* new tmpmesh!

Will remove this call completely in next commit (to make it easier to bisect), I cannot see
any case where object would be assigned with newly generated tmpmesh in this func.

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

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

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

diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c
index b2f5732..0ad3847 100644
--- a/source/blender/blenkernel/intern/mesh.c
+++ b/source/blender/blenkernel/intern/mesh.c
@@ -31,6 +31,7 @@
 
 #include "DNA_scene_types.h"
 #include "DNA_material_types.h"
+#include "DNA_meta_types.h"
 #include "DNA_object_types.h"
 #include "DNA_key_types.h"
 #include "DNA_mesh_types.h"
@@ -2394,23 +2395,25 @@ Mesh *BKE_mesh_new_from_object(
 			}
 			break;
 
-#if 0
-		/* Crashes when assigning the new material, not sure why */
 		case OB_MBALL:
-			tmpmb = (MetaBall *)ob->data;
+		{
+			MetaBall *tmpmb = (MetaBall *)ob->data;
+			tmpmesh->mat = MEM_dupallocN(tmpmb->mat);
 			tmpmesh->totcol = tmpmb->totcol;
 
 			/* free old material list (if it exists) and adjust user counts */
 			if (tmpmb->mat) {
 				for (i = tmpmb->totcol; i-- > 0; ) {
-					tmpmesh->mat[i] = tmpmb->mat[i]; /* CRASH HERE ??? */
+					/* are we an object material or data based? */
+					tmpmesh->mat[i] = ob->matbits[i] ? ob->mat[i] : tmpmb->mat[i];
+
 					if (tmpmesh->mat[i]) {
-						id_us_plus(&tmpmb->mat[i]->id);
+						id_us_plus(&tmpmesh->mat[i]->id);
 					}
 				}
 			}
 			break;
-#endif
+		}
 
 		case OB_MESH:
 			if (!cage) {
@@ -2439,7 +2442,9 @@ Mesh *BKE_mesh_new_from_object(
 	}
 
 	/* make sure materials get updated in object */
-	test_object_materials(ob, &tmpmesh->id);
+	if (ob->data == tmpmesh) {  /* XXX To be removed, there is no reason that ob->data would be new tmpmesh... */
+		test_object_materials(ob, &tmpmesh->id);
+	}
 
 	return tmpmesh;
 }




More information about the Bf-blender-cvs mailing list