[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [33443] trunk/blender/source/blender/ editors/render/render_preview.c: Bugfix #20565

Ton Roosendaal ton at blender.org
Fri Dec 3 15:26:04 CET 2010


Revision: 33443
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=33443
Author:   ton
Date:     2010-12-03 15:26:03 +0100 (Fri, 03 Dec 2010)

Log Message:
-----------
Bugfix #20565

Material Node shaders: displaying GLSL + rendering previews crashed.
Reason was non-safe threaded access to material nodes. Now, on a preview
render, a full copy of Material is being made.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/render/render_preview.c

Modified: trunk/blender/source/blender/editors/render/render_preview.c
===================================================================
--- trunk/blender/source/blender/editors/render/render_preview.c	2010-12-03 12:30:59 UTC (rev 33442)
+++ trunk/blender/source/blender/editors/render/render_preview.c	2010-12-03 14:26:03 UTC (rev 33443)
@@ -148,6 +148,9 @@
 	ID *parent;
 	MTex *slot;
 	
+	/* node materials need full copy during preview render, glsl uses it too */
+	Material *matcopy;
+	
 	int sizex, sizey;
 	unsigned int *pr_rect;
 	int pr_method;
@@ -329,9 +332,9 @@
 		
 		sce->r.color_mgt_flag = scene->r.color_mgt_flag;
 		/* exception: don't color manage texture previews or icons */
-		if((sp && sp->pr_method==PR_ICON_RENDER) || id_type == ID_TE)
+		if((id && sp->pr_method==PR_ICON_RENDER) || id_type == ID_TE)
 			sce->r.color_mgt_flag &= ~R_COLOR_MANAGEMENT;
-		if((sp && sp->pr_method==PR_ICON_RENDER) && id_type != ID_WO)
+		if((id && sp->pr_method==PR_ICON_RENDER) && id_type != ID_WO)
 			sce->r.alphamode= R_ALPHAPREMUL;
 		else
 			sce->r.alphamode= R_ADDSKY;
@@ -340,9 +343,14 @@
 		strcpy(sce->r.engine, scene->r.engine);
 		
 		if(id_type==ID_MA) {
-			Material *mat= (Material *)id;
+			Material *mat= NULL;
 			
 			if(id) {
+				/* work on a copy */
+				mat= copy_material((Material *)id);
+				sp->matcopy= mat;
+				BLI_remlink(&G.main->mat, mat);
+				
 				init_render_material(mat, 0, NULL);		/* call that retrieves mode_l */
 				end_render_material(mat);
 				
@@ -384,7 +392,7 @@
 				}
 
 				
-				if(sp && sp->pr_method==PR_ICON_RENDER) {
+				if(sp->pr_method==PR_ICON_RENDER) {
 					if (mat->material_type == MA_TYPE_HALO) {
 						sce->lay= 1<<MA_FLAT;
 					} 
@@ -400,6 +408,10 @@
 			}
 			else {
 				sce->r.mode &= ~(R_OSA|R_RAYTRACE|R_SSS);
+				
+				free_material(sp->matcopy);
+				MEM_freeN(sp->matcopy);
+				sp->matcopy= NULL;
 			}
 			
 			for(base= sce->base.first; base; base= base->next) {
@@ -428,7 +440,7 @@
 					if(mat && mat->mtex[0]) {
 						mat->mtex[0]->tex= tex;
 						
-						if(sp && sp->slot)
+						if(tex && sp->slot)
 							mat->mtex[0]->which_output = sp->slot->which_output;
 						
 						/* show alpha in this case */
@@ -444,7 +456,7 @@
 				}
 			}
 
-			if(tex && tex->nodetree && sp && sp->pr_method==PR_NODE_RENDER)
+			if(tex && tex->nodetree && sp->pr_method==PR_NODE_RENDER)
 				ntreeInitPreview(tex->nodetree, sp->sizex, sp->sizey);
 		}
 		else if(id_type==ID_LA) {
@@ -987,7 +999,7 @@
 	}
 
 	/* unassign the pointers, reset vars */
-	preview_prepare_scene(sp->scene, NULL, GS(id->name), NULL);
+	preview_prepare_scene(sp->scene, NULL, GS(id->name), sp);
 }
 
 /* runs inside thread for material and icons */





More information about the Bf-blender-cvs mailing list